I am trying to run a script to pass protect all sheets and then give a message box saying either Password correct, or incorrect. The script to actually protect the sheets works well, its the msg boxes which are driving me up the wall. My script is below with the headache area highlighted in green.
Thanks
Sub ProtectAll()
Application.ScreenUpdating = False
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
For Each wSheet In Worksheets
wSheet.Protect Password:=Pwd
Next wSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be protected.", vbCritical, "Incorect Password"
Else
MsgBox "All worksheets protected"
End If
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Sub UnProtectAll()
Application.ScreenUpdating = False
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=Pwd
Next wSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
Else
MsgBox "All worksheets protected"
End If
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Thanks
Sub ProtectAll()
Application.ScreenUpdating = False
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
For Each wSheet In Worksheets
wSheet.Protect Password:=Pwd
Next wSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be protected.", vbCritical, "Incorect Password"
Else
MsgBox "All worksheets protected"
End If
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Sub UnProtectAll()
Application.ScreenUpdating = False
Dim wSheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=Pwd
Next wSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
Else
MsgBox "All worksheets protected"
End If
On Error GoTo 0
Application.ScreenUpdating = True
End Sub