To list all VBA objects (such as buttons, shapes, text boxes, and charts) in an Excel worksheet, you must use a VBA macro that iterates through the Shapes collection of a specific sheet and prints their names and types to a range of cells. Because Excel does not provide a built-in "Object Manager" menu to view every single element on a page, a script is the only way to audit a complex workbook quickly.

What You'll Need

  • Microsoft Excel installed on a Windows or Mac PC.
  • A workbook containing objects (shapes, Form Control buttons, ActiveX controls, or images) to be listed.
  • The Developer tab enabled in the Excel Ribbon.
  • Basic access to the Visual Basic Editor (VBE).

Step-by-Step

  1. Enable the Developer Tab: If you do not see the Developer tab at the top of your Excel window, right-click any existing tab on the Ribbon, select Customize the Ribbon, and in the right-hand column, check the box next to Developer. Click OK. (Note: Menu labels may differ slightly depending on your version of Excel).
  2. Open the Visual Basic Editor: Click the Developer tab and select the Visual Basic button on the far left, or press Alt + F11 on your keyboard. This opens the VBE window where all your code resides.
  3. Insert a New Module: In the VBE, go to the top menu and select Insert > Module. This creates a blank workspace where you can write your custom macro without interfering with the default sheet code.
  4. Enter the Listing Code: Copy and paste the following code into the module window. This specific script is designed to look at the active sheet and list every object it finds starting at cell A1 of a new sheet.
  5. Sub ListAllObjects()
        Dim wsSource As Worksheet
        Dim wsDest As Worksheet
        Dim shp As Shape
        Dim rowNum As Long
    
        Set wsSource = ActiveSheet
        Set wsDest = Sheets.Add
        
        wsDest.Range("A1").Value = "Object Name"
        wsDest.Range("B1").Value = "Object Type"
        wsDest.Range("C1").Value = "Top Position"
        wsDest.Range("D1").Value = "Left Position"
        
        rowNum = 2
        
        For Each shp In wsSource.Shapes
            wsDest.Cells(rowNum, 1).Value = shp.Name
            wsDest.Cells(rowNum, 2).Value = shp.Type
            wsDest.Cells(rowNum, 3).Value = shp.Top
            wsDest.Cells(rowNum, 4).Value = shp.Left
            rowNum = rowNum + 1
        Next shp
        
        MsgBox "Object list complete!"
    End Sub
    
  6. Run the Macro: While still in the VBE, click inside the code block and press F5, or go back to the Excel window, click the Macros button on the Developer tab, select "ListAllObjects", and click Run.
  7. Review the Results: Excel will create a new worksheet. Column A will show the internal name of the object (e.g., "Rectangle 1" or "CommandButton1"), and Column B will show the type code.
  8. Interpret the Type Codes: In the resulting list, the "Object Type" column uses numeric IDs. For example, a value of 1 typically represents a Form Control, while 13 represents a Picture. You can cross-reference these numbers with the official Microsoft VBA ShapeType enumeration.

Common Mistakes

One of the most frequent errors is running the macro while the wrong sheet is active. Since the code uses ActiveSheet, it will only list objects on the page you are currently viewing. If you are on a blank sheet and run the macro, the resulting list will be empty, leading users to believe the code is broken.

Another common mistake is failing to save the workbook as an Excel Macro-Enabled Workbook (.xlsm). If you save the file as a standard .xlsx file, Excel will strip away the VBA module upon closing. When you reopen the file, your listing script will be gone, and you will have to rewrite or re-import the code.

Users also often confuse "Objects" with "Cells" or "Ranges". In VBA terminology, a Shape object is a drawing layer that sits on top of the grid. If you are trying to list named ranges or tables, this specific script will not work because those are part of the Worksheet or Range objects, not the Shapes collection.

Tips

To make the list more useful, you can modify the code to include the object's width and height. Simply add wsDest.Cells(rowNum, 5).Value = shp.Width to the loop. This is incredibly helpful when you are trying to standardize the size of multiple buttons across a professional dashboard.

If you have a massive workbook with dozens of sheets, you can wrap the For Each shp In wsSource.Shapes loop inside another loop that iterates through For Each ws In ThisWorkbook.Worksheets. This allows you to generate a master inventory of every single object across the entire file, which is essential for auditing large-scale corporate templates.

To make the object names easier to manage in the future, use the "Selection Pane" (found under Page Layout > Selection Pane). Once you have used the VBA list to identify an object's name, you can use the Selection Pane to rename it to something intuitive, like "btn_Submit" instead of "Rectangle 42".

Troubleshooting

The macro runs but the list is empty: First, verify that the objects you are looking for are actually "Shapes". If you are using certain types of embedded OLE objects or legacy form elements, they may occasionally be hidden or categorized differently. Ensure you are on the correct sheet before clicking Run.

Error "Subscript out of range": This usually happens if the code tries to reference a sheet name that doesn't exist or if the workbook is protected. If your workbook has a password or protected structure, you must unprotect the workbook via the Review tab before the macro can add a new sheet for the results.

The VBE window is frozen or not responding: This can happen if you have an infinite loop or if the workbook is extremely large. Press Ctrl + Break (or Esc) to force the macro to stop. If the editor remains frozen, save your work in the main Excel window and restart the application.

Macro security warning: If you see a yellow bar stating "Macros have been disabled," click "Enable Content". If this option doesn't appear, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select "Disable VBA macros with notification".

Frequently Asked Questions

Can this list find hidden objects?

Yes, the Shapes collection includes objects that are hidden from view. The VBA script will list them regardless of their visibility status, which is why this method is superior to manually searching the sheet.

Will this work for ActiveX controls?

Yes, ActiveX controls (like ComboBoxes or CommandButtons) are treated as Shape objects in the VBA object model and will appear in the list with their respective type codes.

Can I export this list to a CSV file?

The current script puts the data into a new worksheet. From there, you can simply go to File > Save As and choose "CSV (Comma delimited)" to export the object inventory for external documentation.

Does this work on Excel for Mac?

Yes, the basic Shapes collection and the logic used in this script are compatible with Excel for Mac, though the keyboard shortcuts to open the VBE may differ (use the Tools menu or the Developer tab).

Can I use this to delete all objects at once?

While this script only lists them, you can modify the loop to include shp.Delete. However, it is highly recommended to run the listing script first so you know exactly what will be removed before executing a deletion command.