Consulting

Results 1 to 4 of 4

Thread: Add password to togglebutton code?

  1. #1
    VBAX Regular
    Joined
    Apr 2015
    Posts
    23
    Location

    Add password to togglebutton code?

    Hi,

    Could anyone help me add a password in to the following togglebutton code

    Private Sub ToggleButton21_Click()
    If ToggleButton21.Value = False Then
        ToggleButton21.BackColor = vbGreen
    Else
        ToggleButton21.BackColor = vbRed
    End If
    If ToggleButton21.Value = False Then
    ActiveSheet.Unprotect
    Else
    If ToggleButton21.Value = True Then
    ActiveSheet.Protect
    End If
    End If
    Select Case ToggleButton21.Value
        Case True
            ToggleButton21.Caption = "Locked"
        Case False
            ToggleButton21.Caption = "Unlocked"
    End Select
    End Sub
    thanks
    Jon

  2. #2
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Hi Jon

    How about a simple input box at the beginning of your code?
    Dim Password As String
    Password = InputBox("Please enter password", "Password Required", "********")
    If Password <> "Dunno123" Then
    MsgBox "No way in!"
    Else
    End If
    Above password verification is case sensitive.
    To avoid that, change Dunno123 to DUNNO123 and wrap the function UCase around the input box:
    Password = UCase(InputBox("Please enter password", "Password Required", "********"))

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Could anyone help me add a password in to the following togglebutton code
    Do you mean

    1. ask the user for a password and then protect the sheet with that one, or

    2. just apply a password that is already created to protect / unprotect the sheets?
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Apr 2015
    Posts
    23
    Location
    Hi Paul,

    The code Yongle provided has worked fine - but thanks for the input

    regards
    Jon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •