Shape Object [Excel 2003 VBA Language Reference]
Represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture. The Shape object is a member of the Shapes collection. The Shapes collection contains all the shapes on a slide.
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 Working with Shapes (Drawing Objects) .
Using the Shape Object
This section describes how to:
- Return an existing shape.
- Return a shape within the selection.
- Return the shapes attached to the ends of a connector.
- Return a newly created freeform.
- Return a single shape from within a group.
- Return a newly formed group of shapes.
Returning an Existing Shape
Use Shapes(index), where index is the shape name or the index number, to return a Shape object that represents a shape. The following example horizontally flips shape one and the shape named Rectangle 1 on myDocument.
Set myDocument = Worksheets(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 = Worksheets(1) With myDocument.Shapes.AddShape(msoShapeRectangle, _ 144, 144, 72, 72) .Name = "Red Square" .Fill.ForeColor.RGB = RGB(255, 0, 0) .Line.DashStyle = msoLineDashDot End With
Returning a Shape Within the Selection
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)
Returning the Shapes Attached to the Ends of a Connector
Returning a newly created freeform
Returning a Single Shape from Within a Group
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.
Returning a Newly Formed Group of Shapes
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.
Properties | Adjustments Property | AlternativeText Property | Application Property | AutoShapeType Property | BlackWhiteMode Property | BottomRightCell Property | Callout Property | Child Property | ConnectionSiteCount Property | Connector Property | ConnectorFormat Property | ControlFormat Property | Creator Property | Diagram Property | DiagramNode Property | Fill Property | FormControlType Property | GroupItems Property | HasDiagram Property | HasDiagramNode Property | Height Property | HorizontalFlip Property | Hyperlink Property | ID Property | Left Property | Line Property | LinkFormat Property | LockAspectRatio Property | Locked Property | Name Property | Nodes Property | OLEFormat Property | OnAction Property | Parent Property | ParentGroup Property | PictureFormat Property | Placement Property | Rotation Property | Script Property | Shadow Property | TextEffect Property | TextFrame Property | ThreeD Property | Top Property | TopLeftCell Property | Type Property | VerticalFlip Property | Vertices Property | Visible Property | Width Property | ZOrderPosition Property
Methods | Apply Method | Copy Method | CopyPicture Method | Cut Method | Delete Method | Duplicate Method | Flip Method | IncrementLeft Method | IncrementRotation Method | IncrementTop Method | PickUp Method | RerouteConnections Method | ScaleHeight Method | ScaleWidth Method | Select Method | SetShapesDefaultProperties Method | Ungroup Method | ZOrder Method
Child Objects | Adjustments Object | CalloutFormat Object | ConnectorFormat Object | ControlFormat Object | Diagram Object | DiagramNode Object | FillFormat Object | GroupShapes Object | Hyperlink Object | LineFormat Object | LinkFormat Object | OLEFormat Object | PictureFormat Object | Range Object | ShadowFormat Object | Shape Object | ShapeNodes Object | TextEffectFormat Object | TextFrame Object | ThreeDFormat Object