I have a macro that locks cells once excel is closed, the only problem is that it only works on the first sheet, is there a way for all the sheets to do this, or just one for the wookbook?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim SH As Worksheet
Dim rng As Range
Const PWORD As String = "ABC" '
Set SH = Me.Sheets("SS Record Sheet") '
With SH
.Unprotect Password:=PWORD
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If Not rng Is Nothing Then
.Cells.Locked = False
rng.Cells.Locked = True
.Protect Password:=PWORD
End If
End With
End Sub
Private Sub Workbook_Open()
'check for filter, turn on if none exists
With Worksheets("SS Record Sheet")
If Not .AutoFilterMode Then
.Range("A1").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="ABC", _
Contents:=True, UserInterfaceOnly:=True
End With
End Sub
Bookmarks