Forum Discussion

Michael1105's avatar
Michael1105
Brass Contributor
Jul 31, 2023
Solved

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...
  • HansVogelaar's avatar
    Jul 31, 2023

    Michael1105 

    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

Resources