Shape object (PowerPoint)
Represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.
Remarks
Note
There are three objects that represent shapes: the Shapes collection, which represents all the shapes on a document; the ShapeRange collection, which represents a specified subset of the shapes on a document (for example, a ShapeRange object could represent shapes one and four on the document, or it could represent all the selected shapes on the document); and the Shape object, which represents a single shape on a document. If you want to work with several shapes at the same time or with shapes within the selection, use a ShapeRange collection.
For an overview of how to work with either a single shape or with more than one shape at a time, see Work with shapes (drawing objects).
The following examples describe how to:
Return an existing shape on a slide, indexed by name or number.
Return a newly created shape on a slide.
Return a shape within the selection.
Return the slide title and other placeholders on a slide.
Return the shapes attached to the ends of a connector.
Return the default shape for a presentation.
Return a newly created freeform.
Return a single shape from within a group.
Return a newly formed group of shapes.
Example
Use Shapes (index), where index is the shape name or the index number, to return a Shape object that represents a shape on a slide. The following example horizontally flips shape one and the shape named Rectangle 1 on myDocument.
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes(1).Flip msoFlipHorizontal
myDocument.Shapes("Rectangle 1").Flip msoFlipHorizontal
Each shape is assigned a default name when you add it to the Shapes collection. To give the shape a more meaningful name, use the Name property. The following example adds a rectangle to myDocument, gives it the name Red Square, and then sets its foreground color and line style.
Set myDocument = ActivePresentation.Slides(1)
With myDocument.Shapes.AddShape(Type:=msoShapeRectangle, _
Top:=144, Left:=144, Width:=72, Height:=72)
.Name = "Red Square"
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Line.DashStyle = msoLineDashDot
End With
To add a shape to a slide and return a Shape object that represents the newly created shape, use one of the following methods of the Shapes collection: Add3DModel, AddCallout, AddConnector, AddCurve, AddLabel, AddLine, AddMediaObject, AddOLEObject, AddPicture, AddPlaceholder, AddPolyline, AddShape, AddTable, AddTextbox, AddTextEffect, AddTitle.
Use Selection.ShapeRange (index), where index is the shape name or the index number, to return a Shape object that represents a shape within the selection. The following example sets the fill for the first shape in the selection in the active window, assuming that there's at least one shape in the selection.
ActiveWindow.Selection.ShapeRange(1).Fill _
.ForeColor.RGB = RGB(255, 0, 0)
Use Shapes.Title to return a Shape object that represents an existing slide title. Use Shapes.AddTitle to add a title to a slide that doesn't already have one and return a Shape object that represents the newly created title. Use Shapes.Placeholders (index), where index is the placeholder's index number, to return a Shape object that represents a placeholder. If you have not changed the layering order of the shapes on a slide, the following three statements are equivalent, assuming that slide one has a title.
ActivePresentation.Slides(1).Shapes.Title _
.TextFrame.TextRange.Font.Italic = True
ActivePresentation.Slides(1).Shapes.Placeholders(1) _
.TextFrame.TextRange.Font.Italic = True
ActivePresentation.Slides(1).Shapes(1).TextFrame _
.TextRange.Font.Italic = True
To return a Shape object that represents one of the shapes attached by a connector, use the BeginConnectedShape or EndConnectedShape property.
To return a Shape object that represents the default shape for a presentation, use the DefaultShape property.
Use the BuildFreeform and AddNodes methods to define the geometry of a new freeform, and use the ConvertToShape method to create the freeform and return the Shape object that represents it.
Use GroupItems (index), where index is the shape name or the index number within the group, to return a Shape object that represents a single shape in a grouped shape.
Use the Group or Regroup method to group a range of shapes and return a single Shape object that represents the newly formed group. After a group has been formed, you can work with the group the same way you work with any other shape.
Methods
- Apply
- ApplyAnimation
- ConvertTextToSmartArt
- Copy
- Cut
- Delete
- Duplicate
- Export
- Flip
- IncrementLeft
- IncrementRotation
- IncrementTop
- PickUp
- PickupAnimation
- RerouteConnections
- ScaleHeight
- ScaleWidth
- Select
- SetShapesDefaultProperties
- Ungroup
- UpgradeMedia
- ZOrder
Properties
- ActionSettings
- Adjustments
- AlternativeText
- AnimationSettings
- Application
- AutoShapeType
- BackgroundStyle
- BlackWhiteMode
- Callout
- Chart
- Child
- ConnectionSiteCount
- Connector
- ConnectorFormat
- Creator
- CustomerData
- Decorative
- Fill
- Glow
- GraphicStyle
- GroupItems
- HasChart
- HasInkXML
- HasSmartArt
- HasTable
- HasTextFrame
- Height
- HorizontalFlip
- Id
- InkXML
- IsNarration
- Left
- Line
- LinkFormat
- LockAspectRatio
- MediaFormat
- MediaType
- Model3D
- Name
- Nodes
- OLEFormat
- Parent
- ParentGroup
- PictureFormat
- PlaceholderFormat
- Reflection
- Rotation
- Shadow
- ShapeStyle
- SmartArt
- SoftEdge
- Table
- Tags
- TextEffect
- TextFrame
- TextFrame2
- ThreeD
- Title
- Top
- Type
- VerticalFlip
- Vertices
- Visible
- Width
- ZOrderPosition
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.