PDA

View Full Version : [SOLVED] Add password to togglebutton code?



JonnyB
04-13-2015, 08:03 AM
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

Yongle
04-14-2015, 05:19 AM
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", "********"))

Paul_Hossler
04-14-2015, 09:57 AM
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?

JonnyB
04-14-2015, 01:25 PM
Hi Paul,

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

regards
Jon