Forum Discussion

Jn12345's avatar
Jn12345
Brass Contributor
Nov 27, 2023

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 though it wont run the macro) please see attached photos for more detail. Im wondering if there is a way to make it so that the button doesnt click at all unless the password was correct. The easiest solution is probably to only use a normal button but Im hoping to use the option button i have selected. Please view photos from 1-5

8 Replies

  • Jn12345 

    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...

    • Jn12345's avatar
      Jn12345
      Brass Contributor
      Okay 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
      • Jn12345 

        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

         

Resources