How to: Programmatically Remove Protection from Worksheets

 

You can programmatically remove protection from a Microsoft Office Excel worksheet.

Applies to: The information in this topic applies to document-level projects and VSTO add-in projects for Excel. For more information, see Features Available by Office Application and Project Type.

The following example uses the variable getPasswordFromUser, which contains a password obtained from the user.

To unprotect a worksheet in a document-level customization

  1. Call the Unprotect method of the worksheet and pass in the password, if required. This example assumes that you are working with a worksheet named Sheet1.

                Globals.Sheet1.Unprotect(getPasswordFromUser);
    

To unprotect a worksheet in an VSTO Add-in

  1. Call the _Worksheet.Unprotect method of the active worksheet and pass in the password, if required.

                ((Excel.Worksheet)Application.ActiveSheet).Unprotect(getPasswordFromUser);
    

Working with Worksheets
How to: Programmatically Protect Worksheets
How to: Programmatically Protect Workbooks
How to: Programmatically Hide Worksheets
Global Access to Objects in Office Projects

Show: