Password Protect Macro

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Basically I have a few command buttons on a switchboard (main menu), type sheet, which when clicked on open the appropriate sheet in the workbook.

What I would like to do is to place password on some of these macros, as not all users should have access to all sheets.

Any help on this, or a pointing in the right direction would be great, thanks.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Check out the InputBox function in VBA. You can use something like:

Code:
Dim pword As String
pword = InputBox("Please enter the password:")
If pword <> "abc123" Then
    MsgBox "Incorrect password"
Else
    'Code for correct password
End If
 
Upvote 0
Try:
Code:
Sub ProtectMyPrivates ()
Dim iPassword As String, MyEntry As String
iPassword = "testme" 'or whatever your password is
myentry = InputBox("What is the password?")
If password <> myentry Then
    MsgBox "Incorrect password, macro now stopping"
    Exit Sub
Else
    ' Call your macro
End If

End Sub
 
Upvote 0
Thank you that works.


Now what if I want to place this password on a combobox, so that if the user wants pick an option from the dropdown they need a password?

I can make it so that the user needs to enter a password on every change of the combobox, but I would like the user to only have to enter the password once (until the form is closed). Any idea?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,337
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top