Share via


CanvasShapes Interface

A collection of all the CanvasShapes objects on the specified slide.

Namespace:  Microsoft.Office.Interop.PowerPoint
Assembly:  Microsoft.Office.Interop.PowerPoint (in Microsoft.Office.Interop.PowerPoint.dll)

Syntax

'Declaration
<GuidAttribute("914934EC-5A91-11CF-8700-00AA0060263B")> _
Public Interface CanvasShapes _
    Inherits IEnumerable
'Usage
Dim instance As CanvasShapes
[GuidAttribute("914934EC-5A91-11CF-8700-00AA0060263B")]
public interface CanvasShapes : IEnumerable

Remarks

Each Shape object represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.

Note

If you want to work with a subset of the shapes on a document — for example, to do something to only the AutoShapes on the document or to only the selected shapes — you must construct a ShapeRange collection that contains the shapes you want to work with. For an overview of how to work either with a single shape or with more than one shape at a time, see [Howto:WorkwithShapes(DrawingObjects)#SameCHM].

Examples

Use the Shapes property to return the Shapes collection. The following example selects all the shapes in the active presentation.

ActivePresentation.Slides(1).Shapes.SelectAll

Note

If you want to do something (like delete or set a property) to all the shapes on a document at the same time, use the Range(Object) method with no argument to create a ShapeRange object that contains all the shapes in the Shapes collection, and then apply the appropriate property or method to the ShapeRange object.

Use the AddCallout(MsoCalloutType, Single, Single, Single, Single) , AddComment(Single, Single, Single, Single) , AddConnector(MsoConnectorType, Single, Single, Single, Single) , AddCurve(Object) , AddLabel(MsoTextOrientation, Single, Single, Single, Single) , AddLine(Single, Single, Single, Single) , AddMediaObject(String, Single, Single, Single, Single) , AddOLEObject(Single, Single, Single, Single, String, String, MsoTriState, String, Int32, String, MsoTriState) , AddPicture(String, MsoTriState, MsoTriState, Single, Single, Single, Single) , AddPlaceholder(PpPlaceholderType, Single, Single, Single, Single) , AddPolyline(Object) , AddShape(MsoAutoShapeType, Single, Single, Single, Single) , AddTable(Int32, Int32, Single, Single, Single, Single) , AddTextbox(MsoTextOrientation, Single, Single, Single, Single) , AddTextEffect(MsoPresetTextEffect, String, String, Single, MsoTriState, MsoTriState, Single, Single) , or AddTitleMaster() method to create a new shape and add it to the Shapes collection. Use the BuildFreeform(MsoEditingType, Single, Single) method in conjunction with the ConvertToShape() method to create a new freeform and add it to the collection. The following example adds a rectangle to the active presentation.

ActivePresentation.Slides(1).Shapes.AddShape Type:=msoShapeRectangle, _

    Left:=50, Top:=50, Width:=100, Height:=200

Use Shapes(index), where index is the shape's name or index number, to return a single Shape object. The following example sets the fill to a preset shade for shape one in the active presentation.

ActivePresentation.Slides(1).Shapes(1).Fill _

    .PresetGradient Style:=msoGradientHorizontal, Variant:=1, _

    PresetGradientType:=msoGradientBrass

Use Shapes.Range(index), where index is the shape's name or index number or an array of shape names or index numbers, to return a ShapeRange collection that represents a subset of the Shapes collection. The following example sets the fill pattern for shapes one and three in the active presentation.

ActivePresentation.Slides(1).Shapes.Range(Array(1, 3)).Fill _

    .Patterned Pattern:=msoPatternHorizontalBrick

Use Shapes.Placeholders(index), where index is the placeholder number, to return a Shape object that represents a placeholder. If the specified slide has a title, use Shapes.Placeholders(1) or Shapes.Title to return the title placeholder. The following example adds a slide to the active presentation and then adds text to both the title and the subtitle (the subtitle is the second placeholder on a slide with this layout).

With ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutTitle).Shapes

    .Title.TextFrame.TextRange = "This is the title text"

    .Placeholders(2).TextFrame.TextRange = "This is subtitle text"

End With

See Also

Reference

CanvasShapes Members

Microsoft.Office.Interop.PowerPoint Namespace