Thread: skip worksheet
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default skip worksheet

Maybe you could keep track and then just reprotect the protected worksheets:

Option Explicit
Sub AllSheetsToggleProtectWIndColHide()
'for all sheets in currently active workbook, assigned to button
Dim TopCell As Range
Dim TopCol As Range
Dim Cols2Hide As Range
Dim wkSht As Worksheet
Dim PWORD As String
Dim WksWasProtected As Boolean

PWORD = "pwd"

For Each wkSht In ActiveWorkbook.Worksheets
If LCase(wkSht.Name) = LCase("County Records") Then
'do nothing
Else
With wkSht
If .ProtectContents Then
WksWasProtected = True
.Unprotect Password:=PWORD
.Columns.Hidden = False
Else
WksWasProtected = False
Set TopCell = .Rows(3).Find(What:="top", LookIn:=xlValues)
If TopCell Is Nothing Then ' if it's not found "top"
'what happens here
Else
Set TopCol = .Columns(TopCell.Column)
Set Cols2Hide = .Range(TopCol, .Columns("AC"))
Cols2Hide.Hidden = True
If WksWasProtected Then
.Protect Password:=PWORD
End If
End If
End If
End With
End If
Next wkSht

End Sub

davegb wrote:

Dave asked:
But I'm wondering why you rename the worksheet. Doesn't seem like you
should
have to do this.

The macro renames the worksheets so I can tell they're in unprotected
form.

Both your solutions worked great. Thanks Dave!


--

Dave Peterson