Shapes Object (PowerPoint)
Published: July 16, 2012
A collection of all the Shape objects on the specified slide.
Each Shape object represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.
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 How to: Work with Shapes (Drawing Objects).
Use the Shapes property to return the Shapes collection. The following example selects all the shapes in the active presentation.
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 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 , AddComment , AddConnector , AddCurve , AddLabel , AddLine , AddMediaObject , AddOLEObject , AddPicture , AddPlaceholder , AddPolyline , AddShape , AddTable , AddTextbox , AddTextEffect , or AddTitle method to create a new shape and add it to the Shapes collection. Use the BuildFreeform 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).