Answers for "excel vba Loop through all shapes on a sheet"

VBA
0

excel vba Loop through all shapes on a sheet

' ----------------------------------------------------------------
' Purpose: Loop through all shapes on a sheet
' ----------------------------------------------------------------
Sub loopShapesSheet()

    Dim shp As Shape
    Dim sh As Worksheet

    Set sh = ThisWorkbook.Worksheets("Shape1")

    '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
End Sub
Posted by: Guest on April-18-2022

Code answers related to "VBA"

Browse Popular Code Answers by Language