Skip to main content

How to: Remove a Shape

This example illustrates how to remove a shape.

You can remove an item from the ShapeCollection using the ShapeCollection.RemoveAt method.

worksheet.Shapes.RemoveAt(3);

If a target item is a Chart or Picture object, the ShapeCollection.RemoveAt method call removes this shape from two collections: ShapeCollection and ChartCollection or PictureCollection, respectively.

Call the Shape.Delete method to remove a Shape object directly. The code sample below shows how to remove all connectors from a worksheet.

foreach (Shape shape in worksheet.Shapes)
{
    if (shape.ShapeType == ShapeType.Connector)
        shape.Delete();
}