How to: Protect Workbooks
Some code examples in this topic use the this or Me keyword or the
Theand 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.
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.
To unprotect a workbook
Call the Unprotect method, passing a password if it is required.
Compiling the Code
This code must be placed in the
ThisWorkbookclass, not in a sheet class.