+ Reply to Thread
Results 1 to 3 of 3

Inconsistent macro behavior

  1. #1
    davegb
    Guest

    Inconsistent macro behavior

    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!


  2. #2
    Tom Ogilvy
    Guest

    Re: Inconsistent macro behavior

    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

    --
    Regards,
    Tom Ogilvy


    "davegb" <[email protected]> wrote in message
    news:[email protected]...
    > 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!
    >




  3. #3
    davegb
    Guest

    Re: Inconsistent macro behavior

    Thanks Tom!

    Tom Ogilvy wrote:
    > 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
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "davegb" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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!
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1