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
Can't get the tutorial to work for you? Need help with your code?
Get answers right away at our AE Excel Support Forums!
  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
    • Chetan
      December 8th, 2010 at 06:50
      Reply | Quote | #2

      Hi,

      On the same line can i add autoshapes with predefined witdh & adjustable length with VBA? pls help on how.

      • dharvey
        January 21st, 2011 at 14:16
        Quote | #3

        Sub Fullsizeautoshape()

        ActiveSheet.Shapes.AddShape _
        (msoShapeFlowchartProcess, 39, 252.75, 793, 216).Select
        Selection.ShapeRange.Fill.Visible = msoFalse
        colourChange
        End Sub