ProgrammingVBA - Excel

VBA – Excel – Print All Shape Names Routine

Routine to list names of shapes in specific worksheet or current workbook. Can make adjustments here to list various shape properties.

[code language=”vb”]
Sub RunPrintShapeNames()
‘Specify a single worksheet specified to list shapes in that worksheet
‘ or leave empty to list all shapes within all worksheets in workbook
Dim CWS As Worksheet

Set CWS = ChartSht ‘Change this to specific worksheet object

‘Uncomment line below to specify worksheet name
‘Set CWS = ThisWorkbook.Worksheets("WorksheetName")

Call PrintShapeNames(CWS)
End Sub

Sub PrintShapeNames(Optional InWS As Worksheet)
‘Routine to list all shape names
‘Run from ‘RunPrintShapeNames’ with either a single worksheet specified to list shapes in that worksheet
‘ or leave empty to list all shapes within all worksheets in workbook
Dim CWS As Worksheet
Dim CShape As Shape

If Not InWS Is Nothing Then
For Each CShape In InWS.Shapes
Debug.Print CShape.Name
Next CShape
Else
For Each CWS In ThisWorkbook.Worksheets
For Each CShape In CWS.Shapes
Debug.Print CWS.Name & ": " & CShape.Name
Next CShape
Next CWS
End If

End Sub

[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *