+ Reply to Thread
Results 1 to 16 of 16

Multiple passwords for single Macro

  1. #1
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Multiple passwords for single Macro

    Hey everybody!

    Does anyone know how to protect a single macro with multiple passwords?

    For instance, I've already used the following code to protect a macro:

    If UCase(InputBox("Enter Password")) <> "Password" Then Exit Sub

    I would, however, like to have a "master key" password that works in addition to the password identified above. So basically one unique password for one particular user, and then a master password for an administrator that works for this macro and every other macro in the workbook.

    I currently have about 25 macros (one for each tab) set up and each has a unique password, but I'd like to add a "master" password to each one of these macros.

    Does that make sense?

    Any help would be greatly appreciated!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: Multiple passwords for single Macro

    Does this help?

    http://lastbit.com/excel-article.asp
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    Please Login or Register  to view this content.

    ANOTHER SOL'N
    This solution does not require a password ... what it does is check who is logged into the computer and admits you to the macro based on comparing the login name to the list of people allowed into macro. In my system I take that a step further and have the macro go out to a central spreadsheet that checks for login name to Macro relationship... this allows for central admin of all macro access. Or ... you can have the name listed in each macro .. as it is in this example

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Multiple passwords for single Macro

    Public Const AdminPassword As String = "AdminPass"

    Public Sub DemoPassword()

    Const LocalPassword = "LocalPass"

    pswd = Application.InputBox("Enter Password", "Password")

    If pswd <> LocalPassword And pswd <> AdminPassword Then Exit Sub

    MsgBox "you're in"

    End Sub

    *************

    I tried using this code, but it didn't seem to work at all. When I took out the first two lines and just used the following, it seemed to prompt me for a password and when I used "LocalPass", it worked, but I wasn't able to enter in any other password. Am I missing something? Also, I'm the step before rookie in the coding world, so your patience is greatly appreciated!

    Const LocalPassword = "LocalPass"

    pswd = Application.InputBox("Enter Password", "Password")

    If pswd <> LocalPassword And pswd <> AdminPassword Then Exit Sub

    MsgBox "you're in"

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    "AdminPass" will work ... you do realize these are case sensitive

    maybe upload the book and let me see what you've done .

    did you copy it exaclty as I gave it to you ... or did you attempt to paste it in another macro ? You do realise this is an entire macro and not a snippet to place in another ... this is a demo

    Public Const AdminPassword As String = "AdminPass"
    cannot be removed .. it must sit at top of module,(i.e. outside of macro) so that all macros will know the publicly available admin password.
    Last edited by nimrod; 03-31-2011 at 02:05 PM.

  6. #6
    Forum Contributor
    Join Date
    05-17-2007
    Location
    Michigan, US
    MS-Off Ver
    2007
    Posts
    111

    Re: Multiple passwords for single Macro

    What about a simple If, ElseIf, statement. The first If is the User password check, the ElseIf is the Admin password check, the Else exits the sub.
    Last edited by Spencer; 03-31-2011 at 02:03 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    Your problem isn't the If or the else .. it's that it's not seeing the admin password ... did you include the global Variable declariation of the admin password at the top of the module , outside the macro ?? ie Public Const AdminPassword As String = "AdminPass"

    BY-THE-WAY... I think having the macro validate against the Users Login Name is much better than the password ... passwords get passed around quickly ... while they aren't likely to pass around their Windows username and login.
    Last edited by nimrod; 03-31-2011 at 02:11 PM.

  8. #8
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Multiple passwords for single Macro

    Here is what I currently have in one module:

    Sub CEO()
    If UCase(InputBox("Enter Password")) <> "ELIJAH" Then Exit Sub
    '
    ' CEO Macro
    '

    '
    Sheets("CEO").Select
    End Sub
    Sub COO()
    '
    ' COO Macro
    '

    '
    Sheets("COO").Select
    End Sub
    Sub CAO()
    '
    ' CAO Macro
    '

    '
    Sheets("CAO").Select
    End Sub
    Sub DEV()
    If UCase(InputBox("Enter Password")) <> "MACEVEDO" Then Exit Sub
    '
    ' DEV Macro
    '

    '
    Sheets("DEV").Select
    End Sub
    Sub FIN()
    If UCase(InputBox("Enter Password")) <> "LUBYS" Then Exit Sub
    '
    ' FIN Macro
    '

    '
    Sheets("FIN").Select
    End Sub
    Sub HR()
    If UCase(InputBox("Enter Password")) <> "5JESSICA5" Then Exit Sub
    '
    ' HR Macro
    '

    '
    Sheets("HR").Select
    End Sub
    Sub KTC()
    If UCase(InputBox("Enter Password")) <> "KTC1234" Then Exit Sub
    '
    ' KTC Macro
    '

    '
    Sheets("KTC").Select
    End Sub

    Where do I add the following code:

    Public Const AdminPassword As String = "AdminPass"

    Public Sub DemoPassword()

    Const LocalPassword = "LocalPass"

    pswd = Application.InputBox("Enter Password", "Password")

    If pswd <> LocalPassword And pswd <> AdminPassword Then Exit Sub

    MsgBox "you're in"

    End Sub

    Again, I'm very new to this, sorry for the confusion...

  9. #9
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Multiple passwords for single Macro

    RE: If Elself statement...

    I have no idea what this would be... sorry

  10. #10
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    Please Login or Register  to view this content.

    BY-THE-WAY... I think having the macro validate against the Users Login Name is much better than the password ... passwords get passed around quickly ... while they aren't likely to pass around their Windows username and login.
    Last edited by nimrod; 03-31-2011 at 02:29 PM.

  11. #11
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Multiple passwords for single Macro

    YOU'RE AMAZING!!!!!!! Thank you, thank you, thank you. Sorry I'm so dumb. That's exactly what I needed.

  12. #12
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    Are you interested in seeing an example that doesn't ask for a password... it gives you access based on the name you logged into windows with ???

  13. #13
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Multiple passwords for single Macro

    That might be a little too intense. This is for a small organization and will be used with our budgeting process this year, basically i just wanted to prevent users from being able to change other users budgets and access other info within the book. I appreciate the offer, though! You are way smart.

  14. #14
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    Its really not the intense .. and requires less upkeep... for example here's your CEO macro with it letting people with the windows login names of either nimrod, tellis, or fredk.

    Now the is no need to ask , or maintian passwords.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    10-15-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Multiple passwords for single Macro

    Ok, sweet. I'll give it a whirl. Thanks again - very very helpful stuff.

  16. #16
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Multiple passwords for single Macro

    Here's another solution...
    You have people run "ConfigBookForUser" macro ... when run it automatically knows who is logged in and run's the macros that are set up for that person.

    Note that the old macros have been made private .. so user's can't see or access them directly and that no longer are any passwords needed.


    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1