Forum Discussion
Jn12345
Nov 27, 2023Brass Contributor
Button Macro not to be pressed unless a password is provided
Hello all, So i have an option button and i have a password in my macro so that the code doesnt run unless the correct password is input, however, the issue is that the button still clicks (even ...
HansVogelaar
Nov 27, 2023MVP
If you prompt for the password in the macro associated with the option button, the button has already been clicked when the prompt is displayed. You'd have to turn the button off in the code, but the user will still see it being turned on, then off again...
- Jn12345Nov 29, 2023Brass ContributorOkay im not sure how to do that since im kinda new to macros and when i record what happens when i press the button there is nothing recorded in my VBA. Also i think there is a way to kind of freeze the screen while the macro is being run since i was doing that on some other macros. Ill probably add that to this button also
- HansVogelaarNov 29, 2023MVP
Here is an example:
Sub ClockToDegrees() Dim Password As Variant Password = Application.InputBox(Prompt:="Please Enter Password (WARNING: Date Will Be Cleared)", Type:=2) Select Case Password Case False 'Nothing Case "FT007" ActiveSheet.Unprotect Password:="Protect123!" ' Change the name of the option button as needed ActiveSheet.OptionButtons("Option Button 1").Value = False ' More code here ' ... ActiveSheet.Protect Password:="Protect123!", DrawingObjects:=True, Contents:=True, Scenarios:=True Case Else MsgBox "The Password You Entered Is Incorrect", vbExclamation End Select End Sub
- Jn12345Nov 29, 2023Brass Contributor