Does anybody know how I can get my password to unprotect my multiple sheets. This is what I currently have.
When the workbook closes, it automatically protect all sheets with a specific code I've assigned.
I created a textbox and change the PasswardChar to "*" and I'm using the code below to unprotect the sheets. However, when I enter the password, I get an debug error message. I've tried different ways of using the code, but I can't get one to work. Please help... thank you!
****
Private Sub cmdOK_Click()
Dim WSheet As Worksheet
'Dim Pwd As String
For Each WSheet In Worksheets
If txtPassword = "Test123" Then
WSheet.Unprotect Password:=txtPassword.Value
End If
Next WSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected. Very that the CAPS LOCK key is off.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
Unload Me
End Sub
'The code below is what automatically protects the Sheets when the workbook is closed. This code is in the Workbook.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim i As Long
For i = 1 To Sheets.Count
Sheets(i).Protect Password:="Test123"
Next i
End Sub
When the workbook closes, it automatically protect all sheets with a specific code I've assigned.
I created a textbox and change the PasswardChar to "*" and I'm using the code below to unprotect the sheets. However, when I enter the password, I get an debug error message. I've tried different ways of using the code, but I can't get one to work. Please help... thank you!
****
Private Sub cmdOK_Click()
Dim WSheet As Worksheet
'Dim Pwd As String
For Each WSheet In Worksheets
If txtPassword = "Test123" Then
WSheet.Unprotect Password:=txtPassword.Value
End If
Next WSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected. Very that the CAPS LOCK key is off.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
Unload Me
End Sub
'The code below is what automatically protects the Sheets when the workbook is closed. This code is in the Workbook.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim i As Long
For i = 1 To Sheets.Count
Sheets(i).Protect Password:="Test123"
Next i
End Sub