Buttons in excel 2003

  • Thread starter Thread starter Neil Holden
  • Start date Start date
N

Neil Holden

Hi all, I have a button and when pressed would like to say 'Please enter your
password, once the password has been validated the rest of the macro will run.

Is this possible?
 
Neil,

This a a simple way but you won't get a 'masked' password input box where
the characters typed appear as *** or something else. If you want to do that
then post back

Sub Password()
Dim Response As String
Dim MyPass As String
MyPass = "xxx"
Response = InputBox("Enter your password")
If Response <> MyPass Then
MsgBox "Not Authorised"
Exit Sub
End If
'Your Code

End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
Sorry you wanted a button on the sheet. Put a button on the sheet, right
click it - view code and paste the code below in.

Private Sub CommandButton1_Click()
Dim Response As String
Dim MyPass As String
MyPass = "xxx"
Response = InputBox("Enter your password")
If Response <> MyPass Then
MsgBox "Not Authorised"
Exit Sub
End If
Call YourSubName
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
Try this:
-----------------------------------------
Private Sub CommandButton1_Click()
If InputBox("'Please enter your password") <> "1234" Then
MsgBox "Incorrect Password - Try again"
Exit Sub
Else
MsgBox "Correct Password"
' enter the rest of your code here...
End If
End Sub
 
Back
Top