• Running Macro’s on Password Protected Sheets (97)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Running Macro’s on Password Protected Sheets (97)

    Author
    Topic
    #368546

    I have a rather complex sheet which is accessed by several different users. Password protecting the sheet is a must to protect the structure. However, I also have 3 different command/macro buttons on the form, that set different parameters based on what type of data is being entered. The problem is when the sheet is “password” protected, the macros will stop running, and I get an error message. How can I “code” past the protection, either through un-locking, running the macros, and re-locking, or in some other similar method.

    Viewing 1 reply thread
    Author
    Replies
    • #577851

      just disable the protection, before you actually execute your code, then enable it again

      e.g.
      Sub MyMacro()
      ActiveSheet.Unprotect password:=”MyPassword”
      ‘put your code here
      ActiveSheet.Protect password:=”MyPassword”
      End Sub

      • #577972

        Great. Thanks, it works fine. Second question then. Is it possible to use code to disable the Macro functions under the “Tools” menu, so that the user cannot open the Visual Basic Editor to see the password in the code. Naturally it would be for only this heavily used sheet only.

        • #577984

          No, the user would simply press alt-F11 and access your code.

          You will have to lock your project from view. In the VBE: Tools, VBAProject properties, Protection.

    • #577857

      Unprotect the sheet, do your stuff, then protect it again, like this:

          Worksheets("MyProtectedSheet").Unprotect ("MyPassword")
          'Do your stuff here
          Worksheets("MyProtectedSheet").Protect ("MyPassword")
      
    Viewing 1 reply thread
    Reply To: Running Macro’s on Password Protected Sheets (97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: