Hello again all. I hope you are safe and well.
If this has already been solved here, I did not find it. So I apologize.
I am trying to add a password to a control button placed on a sheet. I do not want the macro attached to the control button to execute unless the password is correct. The following code I used was copied, manipulated, and is on the sheet code area. When the control button is selected, the input box comes up as it should. You can put in the password. When the password is correct, the macro runs. HOWEVER, if you put in the wrong password, the MsgBox opens up and tells you that you put in the incorrect password. Yet the macro still runs when it shouldn't. What did I forget or do wrong?
Thank you in advance!
Jim
If this has already been solved here, I did not find it. So I apologize.
I am trying to add a password to a control button placed on a sheet. I do not want the macro attached to the control button to execute unless the password is correct. The following code I used was copied, manipulated, and is on the sheet code area. When the control button is selected, the input box comes up as it should. You can put in the password. When the password is correct, the macro runs. HOWEVER, if you put in the wrong password, the MsgBox opens up and tells you that you put in the incorrect password. Yet the macro still runs when it shouldn't. What did I forget or do wrong?
VBA Code:
Private Sub CommandButton2_Click()
Dim password As Variant
password = Application.InputBox("Enter Password", "Password Protected")
Select Case password
Case Is = False
'do nothing
Case Is = "ABCDEFG"
Case Else
MsgBox "Incorrect Password"
End Select
WSMaintainance
End Sub
Jim