+ Reply to Thread
Results 1 to 4 of 4

Unhide hidden sheets + Scroll all sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2008
    Posts
    13

    Unhide hidden sheets + Scroll all sheets

    Hi, Im in a little bind that need help.
    Problem:
    1) Need to identify any hidden sheets and unhide them.
    2) Scroll to each sheets starting from the left most
    3) identify if the sheet is protected.

    Project scope.
    Workbook contains between 15 to 25 worksheets.
    Unhide all worksheets, then starting from the left most worksheet.
    Scroll to each one. Unprotect the sheet if protected, then set the print area to print in single page, then protect the sheet again.
    delete sheet if sheetname is Temp1, or work1, or work3, payplan, capture, "Extra (delimited)", or "Temporary (Last month)".

    I hope that I have provide enough information here.
    Thanks for any help...

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Might want to save your workbook first and say no to changes if it doesn't work the way you want.

    Note. Assumes password is blank

    Sub Macro1()
    Dim Arr As Variant
    Dim wsht As Worksheet
    Dim i As Long
    Arr = Array("Temp1", "work1", "work3", "payplan", "capture", """Extra (delimited)""", """Temporary (Last month)""")
    
    For Each wsht In Worksheets
        For i = 0 To UBound(Arr)
        On Error Resume Next
           With wsht
                .Visible = True
                .Unprotect
                If wsht.Name = Arr(i) Then
                Application.DisplayAlerts = False
                   wsht.Delete
                Application.DisplayAlerts = True
            End If
           End With
        
        Next i
    Next wsht
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor
    Join Date
    04-30-2008
    Posts
    105
    Its a bit longer but it should work. If you don't have a Password for these sheets, just delete that part of the code that says "Password:="Password". Also, the code won't cause the macro to stop partially through the code since when you do delete a sheet, Excel will, by default, ask you whether or not you want to permanently delete that particular sheet.

    Sub UnhideSheetsDemo()
      Dim i As Integer
      Dim n As Integer
        
        i = ActiveWorkbook.Sheets.Count
      
        Application.ScreenUpdating = False
      
        For n = 1 To i
      
        If Sheets(n).Visible = False Then
            Sheets(n).Visible = True
        End If
        
        If Sheets(n).Protect Then
            Sheets(n).Unprotect Password:="Password" 'replace with your actual password
            With Sheets(n).PageSetup
                .Orientation = xlPortrait 'change to landscape if that works better
                .PaperSize = xlPaperLetter
                .FitToPagesWide = 1
                .FitToPagesTall = 1
                .PrintErrors = xlPrintErrorsDisplayed
            End With
            Sheets(n).Protect Password:="Password"
       Else
            With Sheets(n).PageSetup
                .Orientation = xlPortrait 'change to landscape if that works better
                .PaperSize = xlPaperLetter
                .FitToPagesWide = 1
                .FitToPagesTall = 1
                .PrintErrors = xlPrintErrorsDisplayed
            End With
    
        End If
        
        Next n
        
        Application.DisplayAlerts = False
        
        On Error Resume Next 'in case any of these files aren't protected and/or actually in the workbook to delete
        If Sheets("Temp1").Protect Then
            Sheets("Temp1").Unprotect Password:="Password"
            Sheets("Temp1").Delete
        Else
            Sheets("Temp1").Delete
        End If
        
        If Sheets("work1").Protect Then
            Sheets("work1").Unprotect Password:="Password"
            Sheets("work1").Delete
        Else
            Sheets("work1").Delete
        End If
        
        If Sheets("work3").Protect Then
            Sheets("work3").Unprotect Password:="Password"
            Sheets("work3").Delete
        Else
            Sheets("work3").Delete
        End If
        
        If Sheets("payplan").Protect Then
            Sheets("payplan").Unprotect Password:="Password"
            Sheets("payplan").Delete
        Else
            Sheets("payplan").Delete
        End If
            
        If Sheets("capture").Protect Then
            Sheets("capture").Unprotect Password:="Password"
            Sheets("capture").Delete
        Else
            Sheets("capture").Delete
        End If
        
        If Sheets("Extra (delimited)").Protect Then
            Sheets("Extra (delimited)").Unprotect Password:="Password"
            Sheets("Extra (delimited)").Delete
        Else
            Sheets("Extra (delimited)").Delete
        End If
        
        If Sheets("Temporary (Last month)").Protect Then
            Sheets("Temporary (Last month)").Unprotect Password:="Password"
            Sheets("Temporary (Last month)").Delete
        Else
            Sheets("Temporary (Last month)").Delete
        End If
        
        On Error GoTo 0
        
        Application.DisplayAlerts = True
        
        Application.ScreenUpdating = True
       
    End Sub
    Hope this helps.
    Last edited by fecurtis; 05-21-2008 at 05:42 PM.

  4. #4
    Registered User
    Join Date
    05-15-2008
    Posts
    13

    Unhide hidden sheets + Scroll all sheets

    Excellent !!! Thanks to both of you.

+ 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