protect all sheets macro crashes when sheet is hidden
try:
Sub ProtectAllWorksheets()
Dim wks As Worksheet
For Each wks In Worksheets
On Error resume next
wks.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingCells:=True,
AllowFormattingColumns:=True,AllowFormattingRows:= True
Next wks
End Sub
Corey....
"Dean" wrote in message
...
I attempted to edit a macro from you folks to protect all sheets, because I
noticed that, if I hid some sheets, then the macro crashed. I added two
rows, the if statement and the rem statement. This is still crashing with
a worksheet hidden. I guess it may be that it can't select a sheet if it
is hidden, so that my if statement is too late, or else my syntax is wrong!
Kindly help.
Thanks!
Dean
Sub ProtectAllWorksheets()
Dim wks As Worksheet
For Each wks In Worksheets
If ActiveSheet.Hidden = True Then GoTo L1
wks.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True
L1: Rem
Next wks
End Sub
|