I am unable to solve this particular problem and seek your kind assistance.
There are times when I need to change the password protection of all my sheets.
After unprotecting all the sheets, I use the following macro to re-protect (with new password) all the sheets:-
***********************************************************
Sub ProtectAllSheets()
Dim pwd1 As String, pwd2 As String
pwd1 = InputBox("Please Enter The New Password")
If pwd1 = "" Then Exit Sub
pwd2 = InputBox("Please Re-enter The New Password")
If pwd2 = "" Then Exit Sub
'Check passwords are identical
If InStr(1, pwd1, pwd2, 0) = 0 Or InStr(1, pwd1, pwd2, 0) = 0 Then
MsgBox "You Entered Different Passwords. No Action Taken"
Exit Sub
End If
For Each ws In Worksheets
ws.Protect Password:=pwd1, UserInterFaceOnly:=True
ws.EnableSelection = xlUnlockedCells
Next
MsgBox "All Sheets Have Been Protected With The New Password."
Exit Sub
End Sub
***********************************************************
Most of my sheets have the following code included to automate current date entry:-
col = Left(Target.Address, 2)
If col = "$D" Then Target.Offset(0, -3) = Now()
***********************************************************
During the session when I protect the sheets, all works well.
However, when I save and close the file and then re-open the file I receive the Run-time error '1004' in every sheet that has the above code and the following code is highlighted:-
Target.Offset(0, -3) = Now()
***********************************************************
Is there additional code or a change of code that is required to overcome this error?
There are times when I need to change the password protection of all my sheets.
After unprotecting all the sheets, I use the following macro to re-protect (with new password) all the sheets:-
***********************************************************
Sub ProtectAllSheets()
Dim pwd1 As String, pwd2 As String
pwd1 = InputBox("Please Enter The New Password")
If pwd1 = "" Then Exit Sub
pwd2 = InputBox("Please Re-enter The New Password")
If pwd2 = "" Then Exit Sub
'Check passwords are identical
If InStr(1, pwd1, pwd2, 0) = 0 Or InStr(1, pwd1, pwd2, 0) = 0 Then
MsgBox "You Entered Different Passwords. No Action Taken"
Exit Sub
End If
For Each ws In Worksheets
ws.Protect Password:=pwd1, UserInterFaceOnly:=True
ws.EnableSelection = xlUnlockedCells
Next
MsgBox "All Sheets Have Been Protected With The New Password."
Exit Sub
End Sub
***********************************************************
Most of my sheets have the following code included to automate current date entry:-
col = Left(Target.Address, 2)
If col = "$D" Then Target.Offset(0, -3) = Now()
***********************************************************
During the session when I protect the sheets, all works well.
However, when I save and close the file and then re-open the file I receive the Run-time error '1004' in every sheet that has the above code and the following code is highlighted:-
Target.Offset(0, -3) = Now()
***********************************************************
Is there additional code or a change of code that is required to overcome this error?