Protect A Worksheet

You can use the Protect method to password protect a worksheet so that other users cannot modify it. You can allow certain types of modifications, such as inserting rows, by specifying the appropriate parameter value for the Protect method.

The Protect method has several different optional parameters that enable you to customize the type of protection that you assign to the workbook. Most of these parameters accept only True or False to indicate whether that type of protection is active for the workbook. The parameters include: Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, and AllowUsingPivotTables.

Although optional, you need to specify the Password parameter to really protect the worksheet. You can use any string, but remember it is case-sensitive. In other words, Excel interprets "Password" and "PASSWORD" differently.

All other parameters of the Protect method accept only True and False values. You use the DrawingObjects parameter to protect any shapes you add to your worksheet. The default value is False. By default, Excel protects the locked cells and scenarios if a worksheet is protected. To remove the protection of locked cells, specify a value of False for the Contents parameter. To unprotect scenarios, specify a value of False for the Scenarios parameter. If you do not use the UserInterfaceOnly parameter, Excel applies the protection to macros and the user interface options for the worksheet. If you only want the user interface protected, specify a value of True for the UserInterfaceOnly parameter.

The other parameters all have default values of False. If you want to allow any of those options when you protect the worksheet, change the value of the corresponding parameter to True.

PROTECT A WORKSHEET

PROTECT A WORKSHEET

^ Create a new subroutine.

—0 Type Worksheets (1).Protect, replacing Worksheets(1) with a reference to the worksheet to protect.

^ Create a new subroutine.

—0 Type Worksheets (1).Protect, replacing Worksheets(1) with a reference to the worksheet to protect.

Was this article helpful?

0 0

Post a comment