Inconsistent macro behavior

  • Thread starter Thread starter davegb
  • Start date Start date
D

davegb

Can anyone tell me why this macro turns on the gridline display on some
worksheets, but not others, in the workbook? It's supposed to show all
sheets, unprotect all sheets, and turn on gridlines on all sheets.

Sub AllSheetsUnhideUnProtectWGrid()
'for all sheets in currently active workbook, assigned to button
'Password
Dim WkSht As Worksheet
Dim PWORD As String
PWORD = "dave"
Application.ScreenUpdating = False

For Each WkSht In ActiveWorkbook.Worksheets
If Not WkSht.Visible Then
WkSht.Visible = True
End If

WkSht.Unprotect Password:=PWORD
ActiveWindow.DisplayGridlines = True
Next WkSht

Application.ScreenUpdating = True

End Sub

As always, thanks in advance!
 
Sub AllSheetsUnhideUnProtectWGrid()
'for all sheets in currently active workbook, assigned to button
'Password
Dim WkSht As Worksheet
Dim PWORD As String
PWORD = "dave"
Application.ScreenUpdating = False

For Each WkSht In ActiveWorkbook.Worksheets
If Not WkSht.Visible Then
WkSht.Visible = True
End If
Wksht.Activate
WkSht.Unprotect Password:=PWORD
ActiveWindow.DisplayGridlines = True
Next WkSht

Application.ScreenUpdating = True

End Sub
 
Thanks Tom!

Tom said:
Sub AllSheetsUnhideUnProtectWGrid()
'for all sheets in currently active workbook, assigned to button
'Password
Dim WkSht As Worksheet
Dim PWORD As String
PWORD = "dave"
Application.ScreenUpdating = False

For Each WkSht In ActiveWorkbook.Worksheets
If Not WkSht.Visible Then
WkSht.Visible = True
End If
Wksht.Activate
WkSht.Unprotect Password:=PWORD
ActiveWindow.DisplayGridlines = True
Next WkSht

Application.ScreenUpdating = True

End Sub
 
Back
Top