Protect Method

Applies To

Chart Object, DialogSheet Object, Module Object, Workbook Object, Worksheet Object.

Description

Protects a chart, dialog sheet, Visual Basic module or worksheet (Syntax 1), or a workbook (Syntax 2) so that it cannot be modified.

Syntax 1

object.Protect(password, drawingObjects, contents, scenarios, userInterfaceOnly)

Syntax 2

object.Protect(password, structure, windows)

object

Required. The Chart, DialogSheet, Module, or Worksheet (Syntax 1) or Workbook object (Syntax 2).

password

Optional. A string that specifies a case-sensitive password for the sheet or workbook. If omitted, you can unprotect the sheet or workbook without a password. If specified, 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. True to protect the drawing objects on the sheet. For a dialog sheet, this protects the layout of the controls. If this argument is omitted, the drawing objects are not protected. Ignored for Visual Basic modules.

contents

Optional. True (or omitted) to protect the contents of the object. For a Visual Basic module, this protects the source code. For a chart, this protects the entire chart. For a dialog sheet, this protects the dialog layout and text of the dialog controls. For a worksheet, this protects the cells.

scenarios

Optional. True (or omitted) to protect scenarios. This argument is valid only for worksheets.

structure

Optional. True to protect the structure of the workbook (the relative position of the sheets). If this argument is omitted, the structure is not protected.

userInterfaceOnly

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

windows

Optional. True to protect the windows of the sheet or workbook. If omitted, the windows are not protected.

Remarks

Using the Protect method causes an error if the workbook is already protected.

See Also

Locked Property, ProtectContents Property, ProtectDrawingObjects Property, ProtectScenarios Property, ProtectStructure Property, ProtectWindows Property, Unprotect Method.

Example

This example protects the active workbook.


ActiveWorkbook.Protect password := "drowssap"