XL97: Protect Method Password Is Not Applied to Worksheet

Last reviewed: March 13, 1998
Article ID: Q161221
The information in this article applies to:
  • Microsoft Excel 97 for Windows

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. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Microsoft Excel 97 allows you to add an additional layer of protection by applying password protection to a previously protected sheet. You can add this protection programmatically.

In earlier versions of Microsoft Excel, using the ActiveSheet.Protect command more than once has no effect. In Microsoft Excel 97, using the command a second time with a password applies password-level security to a previously protected sheet as long as the arguments for Contents, Scenarios, and DrawingObjects are not all set to True. When all the arguments are set to True, Microsoft Excel protects the active sheet but does not apply password-level protection. The value of the UserInterfaceOnly argument has no effect on this behavior.

The following sample code demonstrates the problem:

   Sub Test()

       ActiveSheet.Protect
       ActiveSheet.Protect password:="pw", contents:=True, _
           Scenarios:=True, DrawingObjects:=True, UserInterfaceOnly:=False

   End Sub

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

   protecting information

to go to the "Ways to protect sensitive information" topic.

For more information about the ActiveSheet.Protect command, type "activesheet.protect" (without the quotation marks) on a module sheet and press F1 to display context sensitive Help.


Additional query words: XL97 8.00
Keywords : kbcode kbprg xlvbainfo
Version : WINDOWS:97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.