Hi, recently I needed a way to unprotect all worksheets at once. I was given the idea to create a userform with the following code:
This works great, but if the password entered is wrong, a Run-time error '1004' occurs. Is there any way that a message saying "Incorrect Password" comes up instead of this error?
Thanks!
Code:
Private Sub CommandButton1_Click()
'unprotect worksheets
For Each Worksheet In Worksheets
If Worksheet.ProtectContents = True Then
Worksheet.Unprotect Password:=TextBox1.Text
End If
Next Worksheet
MsgBox "Workbook will be re-protected upon exit."
Unload Me
End Sub
This works great, but if the password entered is wrong, a Run-time error '1004' occurs. Is there any way that a message saying "Incorrect Password" comes up instead of this error?
Thanks!