CB.WorksheetProtection

Crystal Ball cannot run a simulation if a cell with Crystal Ball data is located in a write-protected worksheet. This subroutine is used to supply Crystal Ball with a worksheet password. After that, Crystal Ball uses this password to unlock the worksheet while running and lock it again afterwards.

The following commands will work after CB.WorksheetProtection is called:

Once the CB.WorksheetProtection command has run on each protected worksheet and the workbook saved, nothing else needs to be done for these commands to work.

Call CB.WorksheetProtection with the sheet you want to protect active. It only needs to be called through VBA (for example, from within the VBA Editor) one time for each sheet. Once the code has been run and the workbook saved, the code can be deleted and Crystal Ball will remember the password for future simulations.

It does not matter if the sheet is already protected when CB.WorksheetProtection is called as long as the password passed into the first parameter is consistent with the current worksheet password.

The password is encrypted so users cannot read it.

Table 199. CB.WorksheetProtection Parameters

Parameter

VBA Data Type

Value

Description

aPassword

String

Any alphanumeric string

Specifies the user-assigned password to register for that workbook

aTurnOn

Boolean

True or False

Specifies whether or not workbook protection is active. True activates protection and False removes it

Use this option when you call this macro externally, such as from Visual Basic.