Can anyone tell me why this is not working correctly? I can protect all the sheets but when I go to unprotect the sheets I get the error message?
Sub protectsheets()
Dim wsheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Password:", "Protect Sheets")
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Protect Password:=Pwd, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
Next wsheet
End Sub
Sub unprotectsheets()
Dim wsheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Password:", "Unprotect Sheets")
On Error Resume Next
For Each wsheet In Worksheets
wsheet.Unprotect Password:=Pwd
Next wsheet
If Err <> 0 Then
MsgBox "You have entered an incorrect password. All worksheets could not " & "be unprotected.", vbCritical, "Incorrect Password"
End If
On Error GoTo 0
End Sub
Sub protectsheets()
Dim wsheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Password:", "Protect Sheets")
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Protect Password:=Pwd, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
Next wsheet
End Sub
Sub unprotectsheets()
Dim wsheet As Worksheet
Dim Pwd As String
Pwd = InputBox("Password:", "Unprotect Sheets")
On Error Resume Next
For Each wsheet In Worksheets
wsheet.Unprotect Password:=Pwd
Next wsheet
If Err <> 0 Then
MsgBox "You have entered an incorrect password. All worksheets could not " & "be unprotected.", vbCritical, "Incorrect Password"
End If
On Error GoTo 0
End Sub