P
Paul W Smith
In a code module I have this declaration:
Public Const Password = "Test"
In Thisworkbook I have this code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
ProtectSheets
End Sub
Private Sub ProtectSheets()
Dim WKS As Worksheet
For Each WKS In Worksheets
If WKS.Visible <> xlSheetVeryHidden Then
WKS.Protect Password, DrawingObjects:=True, Contents:=True,
Scenarios:=True
WKS.EnableSelection = xlUnlockedCells
End If
Next WKS
End Sub
The aim is when the workbook is saved all sheets are protected with the
default password.
However after the code runs and the workbook saves itself, the worksheets
cannot be unprotected!!!! Or at least not by entering the password "Test".
Can anyone explain what is happening, and how to achieve what I want to
achieve.
This has happened to me twice now, and after the first time I saved a
back-up before I ran the _BeforeSave code so I would not 'lose' my work.
However can anyone explain this???
Paul Smith
Public Const Password = "Test"
In Thisworkbook I have this code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
ProtectSheets
End Sub
Private Sub ProtectSheets()
Dim WKS As Worksheet
For Each WKS In Worksheets
If WKS.Visible <> xlSheetVeryHidden Then
WKS.Protect Password, DrawingObjects:=True, Contents:=True,
Scenarios:=True
WKS.EnableSelection = xlUnlockedCells
End If
Next WKS
End Sub
The aim is when the workbook is saved all sheets are protected with the
default password.
However after the code runs and the workbook saves itself, the worksheets
cannot be unprotected!!!! Or at least not by entering the password "Test".
Can anyone explain what is happening, and how to achieve what I want to
achieve.
This has happened to me twice now, and after the first time I saved a
back-up before I ran the _BeforeSave code so I would not 'lose' my work.
However can anyone explain this???
Paul Smith