Adding a password on a menu button in excel
The subject line makes reference to a menu button. The explanation makes
reference to buttons on a sheet. That is what this example assumes. (sheet
buttons) It also assumes an ActiveX command button from the control tool box
rather than a command button from the Forms tool bar. This code goes in the
click event procedure for the command button.
You will need to (1) change "CommandButton1" to your command button name.
(2) Replace the word "PASSWORD" with your password. (3) Replace
"run_your_code" with name of the macro you run when data is approved. (4)
Put this code in the code window for the sheet that has the command button.
'This click event prompts the user for a password. Input is not case
sensitive. If the password is valid, the
'???? macro runs. If the password is not valid, a message box is sent. After
OK is clicked, the user is 'prompted for the password again. To terminate
the command, click the Cancel button on the Enter Password 'dialog box.
Private Sub CommandButton1_Click()
Beep
Do
Prompt = Application.InputBox("Enter Password")
If (Prompt = False) Then
Exit Sub
ElseIf (UCase(Prompt) <> "PASSWORD") Then
MsgBox "Invalid Password!", vbCritical
Else
Exit Do
End If
Loop
Call run_your_code
End Sub
HTH
Nelson
Kansas City, MO USA
Quote:
> Dear Friends,
> I have created a template in excel for a user to enter data.
> On the sheet their is 2 buttons. One button is submit and the other is
> approve. Only certain user may approve the data. Can I create a macro that
> when a use click on the approve button he must enter a code before the
> button can be pressed?
> Thank in advance