Export (0) Print
Expand All
Expand Minimize

How to: Protect Workbooks

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The Protect and Unprotect methods allow you to protect a Microsoft Office Excel 2003 workbook so that users cannot add or delete worksheets, and to unprotect the workbook again. You can optionally specify a password, indicate whether you want the structure protected (so users cannot move sheets around), and indicate whether you want the workbook's windows protected.

Protecting a workbook does not stop users from editing cells. To protect the data, you must protect the worksheets. For more information, see How to: Protect Worksheets.

The following code example uses a variable to contain a password obtained from the user:

To protect a workbook

  • Call the Protect method of the workbook and include a password.

    this.Protect(getPasswordFromUser, missing, missing);
    
    

To unprotect a workbook

  • Call the Unprotect method, passing a password if it is required.

    this.Unprotect(getPasswordFromUser);
    
    

Compiling the Code

  • This code must be placed in the ThisWorkbook class, not in a sheet class.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft