PASSWORD PROMPTING CODE

  • Thread starter Thread starter Jay Dean
  • Start date Start date
J

Jay Dean

I have assigned a macro code to a command button in Excel. I need a
macro code to add to my original code that will prompt any user that
pushes the button to enter a password before the code assigned to the
button executes.
Any assistance will be appreciated.Thanks!

Jay Dean.
 
Jay, how about something like this

Sub PassWord_for_Macro()
'must lock VBA project so you can't see the password in it
Dim MyStr1 As String, MyStr2 As String
With ActiveSheet
MyStr2 = ("123") 'change to your password
MyStr1 = InputBox("Password Is Required To Run this Macro ")
If MyStr1 = MyStr2 Then
'*******your code here********
Else
MsgBox ("Password Does Not Match, Access Denied")
End If
End With
End Sub

--
Paul B
Always backup your data before trying something new
Using Excel 2000 & 97
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
 
Jay,

This code uses a simple InputBox to query the user for a password.

Troy


Sub RequestPassword()

Dim sReply As String

sReply = Application.InputBox( _
Prompt:="Please enter the password", _
Title:="Password Required", _
Type:=2)

If sReply = "thePassword" Then
'''Run the password protected code.
MsgBox sReply & " is the correct password"

Else
'''Do not run the password protected code.
MsgBox "Sorry, incorrect password"
End If

End Sub
 
Back
Top