XL97: Protect Method Password Is Not Applied to Worksheet (161221)
The information in this article applies to:
- Microsoft Excel 97 for Windows
This article was previously published under Q161221 SYMPTOMS
When you use the Protect method in a Microsoft Visual Basic for
Applications macro to apply password protection to a worksheet, Microsoft
Excel does not apply the password to the worksheet.
CAUSE
This problem occurs when both 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, 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 either Contents, Scenarios, or DrawingObjects to False.
STATUS
Microsoft has confirmed this to be a problem with the products listed at
the beginning of this article.
REFERENCES
For more information about protecting information in Microsoft Visual Basic
for Applications programming, click the Index tab in Microsoft Visual Basic
Help, type the following text
to go to the "Ways to protect sensitive information" topic.
For more information about the ActiveSheet.Protect command, type
activesheet.protect on a module sheet and
press F1 to display context sensitive Help.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbdtacode kbProgramming KB161221 |
---|
|