View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Howard31 Howard31 is offline
external usenet poster
 
Posts: 100
Default Password To Run Macro?

This one is the same as before, but to avoid the user getting a message -
"Password not valid" when he cancels the Inputbox you should put the
following line of code after the line: 'PwdEntered = InputBox("Please enter
password.")', as follows:

PwdEntered = InputBox("Please enter password.")
If PwdEntered = "" Then Exit Sub
--
A. Ch. Eirinberg


"Howard31" wrote:

How does the user execute the macro? If by clicking a button then in the code
behind the button don't put the macro, instead put the following:

Sub VarifyPWD()
Dim Pwd As String, PwdEntered As String

Pwd = "MyPassword" ' Modify to your chosen password
PwdEntered = InputBox("Please enter password.")

If UCase(PwdEntered) = UCase(Pwd) Then
macro1 'enter the the name of the macro here
Else
MsgBox "Password not valid!", vbCritical
End If
End Sub

In the above code the password will not be case sensitive, if you want the
password to be case sensitive then skip the UCase function

You could create a userform and the textbox which will be used as the
password input, you can asign password charcters like *, so that other people
cannot see what the user enters.

Hope this helps
--
A. Ch. Eirinberg


"garyh" wrote:

Is there a way to request a password when a macro button is clicked? I
would like to 'lock' down the macros.

Thanks.

G