XL2000: Protect Method Password Is Not Applied to Worksheet (213762)
The information in this article applies to:
This article was previously published under Q213762 SYMPTOMS
When you use the Protect method in a Microsoft Visual Basic for
Applications macro to apply password protection to a worksheet, Microsoft
Excel 2000 does not apply the password to the worksheet.
CAUSE
This problem occurs when all of the following conditions are true:
- You use a second ActiveSheet.Protect command that specifies a password in the macro.
-and-
- You set all the arguments (Contents, Scenarios, and DrawingObjects) for the second ActiveSheet.Protect command to True.
NOTE: Microsoft Excel may not apply password protection, depending on the values of the arguments for the Protection statement. In some cases, Microsoft Excel applies worksheet protection but does not apply a password even if you specify a password in the macro.
WORKAROUND
To work around this problem, use either of the following methods.
Method 1
Use the ActiveSheet.Protect command only once and supply all the arguments, including the password. For example, use the following macro:
Sub ProtectSheet()
ActiveSheet.Protect password:="pw", Contents:=True, _
Scenarios:=False, DrawingObjects:=True, UserInterfaceOnly:=True
End Sub
Method 2
Set one of the Protect method arguments to False. To do this, use either of the following methods:
- If the macro is recorded, click to clear one of the following check boxes: Contents, Objects, or Scenarios.
-or-
- If the macro is manually typed, use the following syntax
Sub ProtectSheet()
ActiveSheet.Protect password:="pw", Contents:=True, _
Scenarios:=False, DrawingObjects:=True, _
UserInterfaceOnly:=True
End Sub
to set Contents, Scenarios, or DrawingObjects to False.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCESFor more information about protecting information in Microsoft Visual Basic for Applications programming, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type ways to protect sensitive information in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
| Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
|---|
| Keywords: | kbbug kbdtacode kbpending kbProgramming KB213762 |
|---|
|