How to: Remove Protection from Worksheets

Updated: July 2008

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

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

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

To unprotect a worksheet in a document-level customization

  • 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 application-level add-in

  • Call the _WorksheetUnprotect(Object) method of the active worksheet and pass in the password, if required.

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

Date

History

Reason

July 2008

Added a code example that can be used in an application-level add-in.

Customer feedback.

Community Additions

ADD
Show: