Password to run a Macro?


Posted by Paul Magruder on June 27, 2001 7:16 AM

Is there code that will not allow a Macro to run without a password? I'm using a Button to launch the Macro.

Excel 97 Windows NT
Thanks in advance
Paul

Posted by faster on June 27, 2001 8:29 AM

Here is a possible solution:

Sub MPW()
Dim MyPassword
MyPassword = InputBox("Please enter password", "Password Prompt", "********")

'hardcode password
If MyPassword = "password" Then
MsgBox "Access Granted", vbInformation, "Access"
'call macro
Exit Sub
Else
MsgBox "Access denied", vbCritical, "Error"
Exit Sub
End If
End Sub

Posted by Paul Magruder on June 27, 2001 9:29 AM

Thanks...works great...How do I make it so you only see ******* when the password is entered?

: Is there code that will not allow a Macro to run without a password? I'm using a Button to launch the Macro. : Thanks in advance : Paul



Posted by faster on June 27, 2001 11:15 AM

That's a limitation. You could build a form and use
the same logic. : Dim MyPassword : MyPassword = InputBox("Please enter password", "Password Prompt", "********") : If MyPassword = "password" Then : MsgBox "Access Granted", vbInformation, "Access" : 'call macro : Exit Sub : Else : MsgBox "Access denied", vbCritical, "Error" : Exit Sub : End If : End Sub :