Protect Method

See Also         Example         Applies To

Protects a chart or worksheet (Syntax 1) or a workbook (Syntax 2) so that it cannot be modified.

Syntax 1

expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly)

Syntax 2

expression.Protect(Password, Structure, Windows)

expression   Required. An expression that returns a Chart or Worksheet object (Syntax 1) or a Workbook object (Syntax 2).

Password   Optional Variant. A string that specifies a case-sensitive password for the sheet or workbook. If this argument is omitted, you can unprotect the sheet or workbook without using a password. Otherwise, you must specify the password to unprotect the sheet or workbook. If you forget the password, you cannot unprotect the sheet or workbook. It's a good idea to keep a list of your passwords and their corresponding document names in a safe place.

DrawingObjects   Optional Variant. True to protect shapes. The default value is False.

Contents   Optional Variant. True to protect contents. For a chart, this protects the entire chart. For a worksheet, this protects the individual cells. The default value is True.

Scenarios   Optional Variant. True to protect scenarios. This argument is valid only for worksheets. The default value is True.

Structure   Optional Variant. True to protect the structure of the workbook (the relative position of the sheets). The default value is False.

UserInterfaceOnly   Optional Variant. True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.

Windows   Optional Variant. True to protect the workbook windows. If this argument is omitted, the windows aren’t protected.

Remarks

If you apply the Protect method with the UserInterfaceOnly argument set to True to a worksheet and then save the workbook, the entire worksheet (not just the interface) will be fully protected when you reopen the workbook. To unprotect the worksheet but re-enable user interface protection after the workbook is opened, you must again apply the Protect method with UserInterfaceOnly set to True.