Password required before Macro execution

A

Andy Tallent

What I would like to do is have a password box appear prior to a macro
executing. In the example I'm citing I have a macro keying off a
CommandButton but I don't want all users to be able to execute this macro,
only those with the password. Is this possible.

As always I am appreciative of your patience.
 
E

eluehmann

Sub password()
CC = InputBox("Please enter the password:")
If CC = "password" Then
'PUT MACRO HERE
MsgBox ("Macro Execution")
End If
End Sub
 
J

JE McGimpsey

One way:

At the beginning of your macro, put something like

Const sPASSWORD As String = "drowssap"
Dim vResponse As Variant
Do
vResponse = Application.InputBox("Enter the Password")
If vResponse = False Then Exit Sub 'User Cancelled
Loop Until vResponse = sPASSWORD
 
A

Andy Tallent

Thank you, this works beautifully.

JE McGimpsey said:
One way:

At the beginning of your macro, put something like

Const sPASSWORD As String = "drowssap"
Dim vResponse As Variant
Do
vResponse = Application.InputBox("Enter the Password")
If vResponse = False Then Exit Sub 'User Cancelled
Loop Until vResponse = sPASSWORD
 
Top