Answers for "excel vba Loop through all shapes in a workbook"

VBA
0

excel vba Loop through all shapes in a workbook

' ----------------------------------------------------------------
' Purpose: Loop through all shapes on all sheets in a workbook
' ----------------------------------------------------------------
Sub loopShapesAllSheet()

    Dim shp As Shape
    Dim sh As Worksheet

    'Loop through all the sheets in a workbook
    For Each sh In ThisWorkbook.Worksheets

        'If there is any shape on the sheet
        If sh.Shapes.Count > 0 Then
            'Loop through all the shapes on the sheet
            For Each shp In sh.Shapes
        
                'Print to immediate window shape type, shape name and sheet name holding the shape
                'Useful link: https://msdn.microsoft.com/en-us/VBA/Office-Shared-VBA/articles/msoshapetype-enumeration-office
                Debug.Print shp.Type & vbTab & shp.Name & vbTab & shp.Parent.Name
        
            Next shp
        End If
    Next sh
End Sub
Posted by: Guest on April-18-2022

Code answers related to "VBA"

Browse Popular Code Answers by Language