Partager via


Worksheet.Protect Method

Definition

Protects a worksheet so that it cannot be modified.

public void Protect (object Password, object DrawingObjects, object Contents, object Scenarios, object UserInterfaceOnly, object AllowFormattingCells, object AllowFormattingColumns, object AllowFormattingRows, object AllowInsertingColumns, object AllowInsertingRows, object AllowInsertingHyperlinks, object AllowDeletingColumns, object AllowDeletingRows, object AllowSorting, object AllowFiltering, object AllowUsingPivotTables);
abstract member Protect : obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj * obj -> unit
Public Sub Protect (Optional Password As Object, Optional DrawingObjects As Object, Optional Contents As Object, Optional Scenarios As Object, Optional UserInterfaceOnly As Object, Optional AllowFormattingCells As Object, Optional AllowFormattingColumns As Object, Optional AllowFormattingRows As Object, Optional AllowInsertingColumns As Object, Optional AllowInsertingRows As Object, Optional AllowInsertingHyperlinks As Object, Optional AllowDeletingColumns As Object, Optional AllowDeletingRows As Object, Optional AllowSorting As Object, Optional AllowFiltering As Object, Optional AllowUsingPivotTables As Object)

Parameters

Password
Object

A case-sensitive password for the worksheet. If this argument is omitted, you can unprotect the worksheet without using a password. Otherwise, you must specify the password to unprotect the worksheet. If you forget the password, you cannot unprotect the worksheet. It is a good idea to keep a list of your passwords and their corresponding document names in a safe place.

DrawingObjects
Object

true to protect shapes. The default value is false.

Contents
Object

true to protect contents in the locked cells. The default value is true.

Scenarios
Object

true to protect scenarios. The default value is true.

UserInterfaceOnly
Object

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

AllowFormattingCells
Object

true allows the user to format any cell on a protected worksheet. The default value is false.

AllowFormattingColumns
Object

true allows the user to format any column on a protected worksheet. The default value is false.

AllowFormattingRows
Object

true allows the user to format any row on a protected worksheet. The default value is false.

AllowInsertingColumns
Object

true allows the user to insert columns on the protected worksheet. The default value is false.

AllowInsertingRows
Object

true allows the user to insert rows on the protected worksheet. The default value is false.

AllowInsertingHyperlinks
Object

true allows the user to insert hyperlinks on the worksheet. The default value is false.

AllowDeletingColumns
Object

true allows the user to delete columns on the protected worksheet, where every cell in the column to be deleted is unlocked. The default value is false.

AllowDeletingRows
Object

true allows the user to delete rows on the protected worksheet, where every cell in the row to be deleted is unlocked. The default value is false.

AllowSorting
Object

true allows the user to sort on the protected worksheet. Every cell in the sort range must be unlocked or unprotected. The default value is false.

AllowFiltering
Object

true allows the user to set filters on the protected worksheet. Users can change filter criteria but can not enable or disable an autofilter. Users can set filters on an existing autofilter. The default value is false.

AllowUsingPivotTables
Object

true allows the user to use pivot table reports on the protected worksheet. The default value is false.

Remarks

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

It is possible to make changes to a protected worksheet if the password is supplied. Also, another method would be to unprotect the worksheet, make the necessary changes, and then protect the worksheet again.

Note

'Unprotected' means the cell may be locked (Format Cells dialog) but is included in a range defined in the Allow Users to Edit Ranges dialog, and the user has unprotected the range with a password or been validated via NT permissions.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to