Unhiding or Listing All Objects

Written by Allen Wyatt (last updated June 12, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


Mike had a problem where he knew that there were objects hidden within his workbook and he wanted to find them all. It seems he wrote a macro that hid some objects, but then did not unhide them.

If you want to simply find out the names of the objects in a worksheet, the following macro will do so very nicely. It shows not only the name, but also the type of object.

Sub ListObjects()
    Dim objCount As Integer
    Dim x As Integer
    Dim objList As String
    Dim objPlural As String
    Dim objType(17) As String

    'Set types for different objects
    objType(1) = "Autoshape"
    objType(2) = "Callout"
    objType(3) = "Chart"
    objType(4) = "Comment"
    objType(7) = "EmbeddedOLEObject"
    objType(8) = "FormControl"
    objType(5) = "Freeform"
    objType(6) = "Group"
    objType(9) = "Line"
    objType(10) = "LinkedOLEObject"
    objType(11) = "LinkedPicture"
    objType(12) = "OLEControlObject"
    objType(13) = "Picture"
    objType(14) = "Placeholder"
    objType(15) = "TextEffect"
    objType(17) = "TextBox"

    objList = ""

    'Get the number of objects
    objCount = ActiveSheet.Shapes.Count

    If objCount = 0 Then
        objList = "There are no shapes on " & _
          ActiveSheet.Name
    Else
        objPlural = IIf(objCount = 1, "", "s")
        objList = "There are " & Format(objCount, "0") _
          & " Shape" & objPlural & " on " & _
          ActiveSheet.Name & vbCrLf & vbCrLf
        For x = 1 To objCount
            objList = objList & ActiveSheet.Shapes(x).Name & _
              " is a " & objType(ActiveSheet.Shapes(x).Type) _
              & vbCrLf
        Next x
    End If

    MsgBox (objList)

End Sub

This macro returns the names and types of all objects in the worksheet. Another approach, however, is to display all the object names and then, if the object is hidden, ask if you want it unhidden. The following macro does just that:

Sub ShowEachShape1()
    Dim sObject As Shape
    Dim sMsg As String
    For Each sObject In ActiveSheet.Shapes
        sMsg = "Found " & IIf(sObject.Visible, _
          "visible", "hidden") & " object " & _
          vbNewLine & sObject.Name
        If sObject.Visible = False Then
            If MsgBox(sMsg & vbNewLine & "Unhide ?", _
              vbYesNo) = vbYes Then
                sObject.Visible = True
            End If
        Else
            MsgBox sMsg
        End If
    Next
End Sub

If you want the macro to only work on hidden objects and ignore those that are visible, then you can modify the macro to the following:

Sub ShowEachShape2()
    Dim sObject As Shape
    Dim sMsg As String
    For Each sObject In ActiveSheet.Shapes
        If sObject.Visible = False Then
            sMsg = "Object & sObject.Name & _
              " is hidden. Unhide it?"
            If MsgBox(sMsg, vbYesNo) = vbYes Then
                sObject.Visible = True
            End If
        End If
    Next
End Sub

To simply make all the objects visible in one step, you can shorten the macro even more:

Sub ShowEachShape3()
    Dim sObject As Shape
    For Each sObject In ActiveSheet.Shapes
        sObject.Visible = True
    Next
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2025) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Replacing in Worksheets and Comments At the Same Time

If you need to replace information that may appear in cells, comments, and text boxes, your best bet is to use a macro. ...

Discover More

Examining Tracked Changes in a Macro

The Track Changes feature in Word is very handy when you need to see what edits are made to a document. Using a macro, ...

Discover More

Outside End Data Label for a Column Chart

It can be frustrating when Excel doesn't display the formatting options that you know it should for your charts. This tip ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Understanding the If ... End If Structure

One of the most basic of programming structures is the conditional structure: If ... End If. This tip explains how this ...

Discover More

Adding a Macro to a Toolbar

A great way to customize Excel is to add your macros to a toolbar. That way you can run them quickly and easily.

Discover More

Controlling the Behavior of the Mouse Wheel

The mouse wheel, by default, controls scrolling vertically through your worksheet. If you don't want the wheel to control ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.