Forum Discussion
Michael1105
Jul 31, 2023Brass Contributor
Multiple worksheet protection VBA code
Hello Excel Experts, I have the VBA coding to protect and unprotect multiple worksheets. The code only requires the password entry once before locking down the worksheets. Are there lines that can...
- Jul 31, 2023
For example
Dim PW1 As String Dim PW2 As String PW1 = InputBox("Enter the password") If PW1 <> "" Then Do PW2 = InputBox("Enter the password again") If PW2 = PW1 Then Exit Do ElseIf MsgBox("The password doesn't match!" & vbCrLf & _ "Do you want to cancel?", vbQuestion + vbYesNo) = vbYes Then ' Decide what do do here Exit Do End If Loop End If
HansVogelaar
Jul 31, 2023MVP
For example
Dim PW1 As String
Dim PW2 As String
PW1 = InputBox("Enter the password")
If PW1 <> "" Then
Do
PW2 = InputBox("Enter the password again")
If PW2 = PW1 Then
Exit Do
ElseIf MsgBox("The password doesn't match!" & vbCrLf & _
"Do you want to cancel?", vbQuestion + vbYesNo) = vbYes Then
' Decide what do do here
Exit Do
End If
Loop
End If- Michael1105Aug 08, 2023Brass ContributorHansVogelaar
Thank you very much. I apologize for not replying sooner. I wasn't aware there was a response because I didn't receive an email. I appreciate your assitance.