Follow this blog:
RSS
Email Alert

Microsoft Office

Use VBA to find hidden Excel sheets

Takeaway: Excel’s ThisWorkbook object lets you expose and change a worksheet’s visibility.

If you have hidden sheets in Excel, it might be helpful to programmatically manipulate those sheets. You might want to hide or unhide a sheet or just run an audit to make sure no one has changed your settings. The following sub procedure prints the visibility status of each sheet in the workbook:

Private Sub ReportVisibility()

  ‘List very hidden sheets in Immediate window

  Dim ws As Worksheet

  For Each ws In ThisWorkbook.Worksheets

    If ws.Visible = xlSheetVeryHidden Then

      Debug.Print ws.Name & ” is very hidden”

    ElseIf ws.Visible = xlSheetHidden Then

      Debug.Print ws.Name & ” is hidden”

    End If

Next

End Sub

  

Of course, you can modify this procedure to do most anything you want with the hidden sheets. Just add the appropriate code to the If statement. This particular sub doesn’t explicitly identify visible sheets. Anything not listed should be visible. If you want to see a comprehensive list of all sheets, add a condition for visible–xlSheetVisible.

Get IT Tips, news, and reviews delivered directly to your inbox by subscribing to TechRepublic’s free newsletters.

Susan Harkins

About Susan Harkins

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

Susan Harkins

Susan Harkins
Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.
5
Comments

Join the conversation!

Follow via:
RSS
Email Alert