Vba password prompt on Excel macro / password to restrict access to macros

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
Hi, I hope this is an easy one someone could help with - how do you put a password prompt in a macro so that it brings up a message box asking the user to enter a password before the macro runs successfully? Also is it possible to password restrict all macros so that no one came go in and alter the script/text - only you can see and edit with the password? Thanks in advance. David
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You can use the below lines before your VBA code

Code:
Sub ABC()

Dim Pass As String
Pass = "Test"

If InputBox("Please enter the password to run the macro") <> Pass Then
    MsgBox "Incorrect password !", vbExclamation, "Error"
    Exit Sub
End If

'place your VBA code here

End Sub

To protect the VBE, click on Tools > VBA Project Properties > Protection > Password
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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