VBA: Delete All Autoshapes

November 29th, 2004 | Categories: VBA | Tags:

The following is a Macro to delete all of the Autoshapes on a given worksheet.

deleteautoshapes

Sub DeleteAllShapes()

'Activate sheet to delete autoshapes.
Sheet1.Activate

Dim GetShape As Shape

    For Each GetShape In ActiveSheet.Shapes
        GetShape.Delete
    Next

End Sub
  1. December 2nd, 2004 at 00:10
    Reply | Quote | #1

    Hi.

    Along a similar line.
    I built this code to delete shapes within a given range.

    Setting cDeleteOnTouch to True has a different effect.
    ie. Range is just touching or range fully covers shape?

    Sub test()
        Const cDeleteOnTouch As Boolean = False
        Dim rng As Range, shp As Shape, rngSelect As Range, blnDelete As Boolean
    
        Set rngSelect = Selection
    
        For Each shp In ActiveSheet.Shapes
            blnDelete = False
            Set rng = Intersect(Range(shp.TopLeftCell, shp.BottomRightCell), rngSelect)
            If cDeleteOnTouch Then
                If Not rng Is Nothing Then blnDelete = True
            Else
                If Not rng Is Nothing Then
                    If rng.Address = Range(shp.TopLeftCell, shp.BottomRightCell).Address Then blnDelete = True
                End If
            End If
    
            If blnDelete Then
                MsgBox "delete " & shp.Name
                'shp.Delete
            End If
        Next
    End Sub