Version

Protect(String,Boolean,Boolean) Method

Protects the worksheet with the specified password.
Syntax
'Declaration
 
Public Overloads Sub Protect( _
   ByVal password As String, _
   Optional ByVal allowEditStructure As Boolean, _
   Optional ByVal allowEditWindows As Boolean _
) 
public void Protect( 
   string password,
   bool allowEditStructure,
   bool allowEditWindows
)

Parameters

password
The password used to protect the Worksheet.
allowEditStructure
Optional boolean indicating the new value for the WorkbookProtection.AllowEditStructure.
allowEditWindows
Optional boolean indicating the new value for the WorkbookProtection.AllowEditWindows.
Remarks

When a Workbook is protected without a password, the end user may unprotect the Workbook in Excel without having to supply a password. To programatically unprotect a Workbook, one may use the Unprotect method.

When a Workbook is protected, the values of the properties of the WorkbookProtection instance from this Workbook's Protection property indicate the disabled operations.

Note: If IsProtected is already true, the method will be ignored.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also