Password Problem


Posted by Paul Magruder on July 31, 2001 3:45 AM

I am using a password to allow a user access to run a macro. The problem is the user has to enter the password everytime they press the button to run the macro. What I would like is for the user to only have to enter the password the first time they press the button, and not have to enter the password the remainder of times they run the macro until the workbook is closed. ....Excel 2000

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

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



Posted by Jerid on July 31, 2001 5:33 AM

Paul, try this.

'Make MyPassword a Global Variable
Public MyPassword As String

Sub MPW()

If MyPassword <> "performance" Then
MyPassword = InputBox("Please enter password", "Password Prompt", "********")
ElseIf MyPassword = "performance" Then
MsgBox "Access Granted", vbInformation, "Access"
Call Performance
Exit Sub
Else
MsgBox "Access denied", vbCritical, "Error"
Exit Sub
End If
End Sub

Jerid