Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password protected command button

Status
Not open for further replies.

UNDPC

MIS
Dec 18, 2003
57
US
Hi,
I have created a macro that is run by clicking a command button on an excel worksheet. I want to place a password on the command button so that the macro will only run if the correct password is entered. Is there an easy way to do this, or will a decent amount of code need to be written? Any help is appreciated.
 
Hi,

This depends on how secure you want the password to be. If you feel sure enough that the person pushing the button won't be able to open the macro and look at it, you can simply do a compare between a preset variable and the text entered in a pop-up box triggered by the button push.

Not sure how you would do it some other way though.

Josh
 
Bit of a brain fart here but give it a go - haven't xl on this PC so no way to test it:

Private Sub CommandButton1_Click()
On Error GoTo oops
Dim Password As String, ComparePW As String
Password = "YourPasswordHere"
ComparePW = InputBox("PW")
If Len(ComparePW) = 0 Then Exit Sub
If ComparePW = Password Then
MsgBox "Hello" 'do something here
End If
Exit Sub

oops:
MsgBox "Fcuked up there!"
End Sub


Needs some tweaking!

Chris ;-)

Visit for great xl and xl/VBA help
 
Thanks guys. I actually ended up doing exactly this while waiting to see if anyone responded to the post. Guess I had it right all along. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top