Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Michigan, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Password to Run Macro (Office 2000-2003)

    Is there a way to password a macro so that when you try to run it you have to enter a password? I searched the Lounge and though there are some references to being able to do such a thing there are no actual steps for doing so. Either that or my seach string had the Monday morning stupids <img src=/S/smile.gif border=0 alt=smile width=15 height=15>.

    TIA
    <font face="Comic Sans MS"><big><font color=4682b4>Sherry</font color=4682b4></big></font face=comic>

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Password to Run Macro (Office 2000-2003)

    Hi Sherry

    This is a very unsafe method as any one who is VBA could see it, but it could be used as a safety catch:


    Sub Password()
    Dim Message, Title, strPassword
    Message = "Enter Password"
    Title = "Password?"
    strPassword = InputBox(Message, Title)

    If strPassword = "Lounge" Then

    MsgBox "You can put you code here"

    Else
    End If


    End Sub
    Jerry

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Password to Run Macro (Office 2000-2003)

    Hi Jezza,

    Password-protecting the vba project should prevent most people from being able to see the hard-coded password. If you don't at least do that, what's the point of having the code password-protected (anyone with access to the project could change/delete the passowrd, or simply comment-out the test)?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Michigan, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password to Run Macro (Office 2000-2003)

    Jerry,
    I'm not sure I understand how to use your code. I have a macro that will unprotect all sheets in the workbook and I want only the Financial Analysts to be able to run the macro. Where would I put your code?

    Public Sub UnprotectAllSheets()
    Dim oSheet As Worksheet
    For Each oSheet In Sheets
    oSheet.Unprotect ("unique")
    Next oSheet
    End Sub

    Thanks.
    <font face="Comic Sans MS"><big><font color=4682b4>Sherry</font color=4682b4></big></font face=comic>

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Password to Run Macro (Office 2000-2003)

    Jerry is offline at the moment, he probably meant something like this:

    Public Sub UnprotectAllSheets()
    Dim oSheet As Worksheet
    If InputBox("Enter Password", "Password") = "Lounge" Then
    For Each oSheet In Sheets
    oSheet.Unprotect "unique"
    Next oSheet
    Else
    MsgBox "You don't have permission to run this macro!", vbCritical
    End If
    End Sub

    If you wish you can use the same password for running the macro and for unprotecting the sheets.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Password to Run Macro (Office 2000-2003)

    Thanks Macropod

    That was my point about being unsafe, but password protecting the module would be the solution
    Jerry

  7. #7
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Michigan, USA
    Posts
    408
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Password to Run Macro (Office 2000-2003)

    Thanks Hans! It looks like just what I want. I will try it.
    <font face="Comic Sans MS"><big><font color=4682b4>Sherry</font color=4682b4></big></font face=comic>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •