Excel vba删除工作簿上所有shape形状

2019-11-05 16:21:00
tmtony8
原创
83

如果表格中有多个shape形状,如果需要全部删除,是否有更好的办法?


下面代码遍历整个工作簿,逐个工作表批量删除所有形状对象

Public Sub Del_Shapes()
    Dim sht As Worksheet
    Dim p As Shape
    Dim arr(), n%
    For Each sht In Worksheets
        For Each p In sht.Shapes
            If p.Type = 1 Then n = n + 1
            ReDim Preserve arr(1 To n):
            arr(n) = p.Name
        Next p
        If n > 0 Then sht.Shapes.Range(arr).Delete
        n = 0
    Next sht
End Sub



删除结果

    分享