You are on page 1of 3

EXCEL MACROS

1. Delete All Shapes on Spreadsheet


Sub DeleteAllShapes()
'PURPOSE: Remove All Shape Objects From The Active Worksheet
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim shp As Shape

For Each shp In ActiveSheet.Shapes
   shp.Delete
Next shp

End Sub

2. Excluding certain shapes


3. Sub DeleteAllShapes()
'PURPOSE: Remove All Shape Objects From The Active Worksheet
(Excludes Charts/Comments)
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim shp As Shape

For Each shp In ActiveSheet.Shapes
  If shp.Type <> msoChart And shp.Type <>
msoComment Then shp.Delete
Next shp

End Sub

Below is a table of all the msoShapeType properties that you can use in your IF statement to
exclude certain shape types from being deleted. You can use the full name or the enumeration
in your code.
Name Enum Type

msoAutoShape 1 AutoShape

msoCallout 2 Callout

msoCanvas 20 Canvas
msoChart 3 Chart

msoComment 4 Comment

msoContentApp 27 Content Office Add-in

msoDiagram 21 Diagram

msoEmbeddedOLEObject 7 Embedded OLE object

msoFormControl 8 Form Control

msoFreeform 5 Freeform

msoGraphic 28 Graphic

msoGroup 6 Group

msoIgxGraphic 24 SmartArt Graphic

msoInk 22 Ink

msoInkComment 23 Ink Comment

msoLine 9 Line

msoLinkedGraphic 29 Linked Graphic


msoLinkedOLEObject 10 Linked OLE object

msoLinkedPicture 11 Linked Picture

msoMedia 16 Media

msoOLEControlObject 12 OLE Control Object

msoPicture 13 Picture

msoPlaceholder 14 Placeholder

msoScriptAnchor 18 Script Anchor

msoShapeTypeMixed -2 Mixed Shape Type

msoTable 19 Table

msoTextBox 17 Text Box

msoTextEffect 15 Text Effect

msoWebVideo 26 Web Video

You might also like