Shapes Collection Object
Description
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.
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 Working with Shapes (Drawing Objects).
Using the Shapes Collection
Use the Shapes property to return the Shapes collection. The following example selects all the shapes on myDocument.
Set myDocument = ActivePresentation.Slides(1)
myDocument.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 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, 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 myDocument.
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 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 on myDocument.
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes(1).Fill.PresetGradient msoGradientHorizontal, 1, _
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 on myDocument.
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.Range(Array(1, 3)).Fill.Patterned _
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).
Set myDocument = ActivePresentation.Slides(1)
With ActivePresentation.Slides.Add(1, ppLayoutTitle).Shapes
.Title.TextFrame.TextRange = "This is the title text"
.Placeholders(2).TextFrame.TextRange = "This is subtitle text"
End With
Properties
Application property, Count property, Creator property, HasTitle property, Parent property, Placeholders property, Title property.
Methods
AddCallout method, AddComment method, AddConnector method, AddCurve method, AddLabel method, AddLine method, AddMediaObject method, AddOLEObject method, AddPicture method, AddPlaceholder method, AddPolyline method, AddShape method, AddTextbox method, AddTextEffect method, AddTitle method, BuildFreeform method, Item method (multiple collections), Paste method, Range method, SelectAll method.