ShapeRange Collection [Excel 2003 VBA Language Reference]
Represents a shape range, which is a set of shapes on a document. A shape range can contain as few as a single shape or as many as all the shapes on the document. You can include whichever shapes you want — chosen from among all the shapes on the document or all the shapes in the selection — to construct a shape range. For example, you could construct a ShapeRange collection that contains the first three shapes on a document, all the selected shapes on a document, or all the freeforms on a document.
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 ShapeRange Collection
This section describes how to:
- Return a set of shapes you specify by name or index number.
- Return all or some of the selected shapes on a document.
Returning a Set of Shapes You Specify by Name or Index Number
Use Shapes.Range(index), where index is the name or index number of the shape or an array that contains either names or index numbers of shapes, to return a ShapeRange collection that represents a set of shapes on a document. You can use the Array function to construct an array of names or index numbers. The following example sets the fill pattern for shapes one and three on
Set myDocument = Worksheets(1) myDocument.Shapes.Range(Array(1, 3)).Fill.Patterned _ msoPatternHorizontalBrick
The following example sets the fill pattern for the shapes named Oval 4 and Rectangle 5 on myDocument.
Set myDocument = Worksheets(1) Set myRange = myDocument.Shapes.Range(Array("Oval 4", _ "Rectangle 5")) myRange.Fill.Patterned msoPatternHorizontalBrick
Although you can use the Range property to return any number of shapes or slides, it's simpler to use the Item method if you want to return only a single member of the collection. For example,
Shapes(1) is simpler than
Returning All or Some of the Selected Shapes on a Document
Use the ShapeRange property of the Selection object to return all the shapes in the selection. The following example sets the fill foreground color for all the shapes in the selection in window one, assuming that there's at least one shape in the selection.
Windows(1).Selection.ShapeRange.Fill.ForeColor.RGB = _ RGB(255, 0, 255)
Use Selection.ShapeRange(index), where index is the shape name or the index number, to return a single shape within the selection. The following example sets the fill foreground color for shape two in the collection of selected shapes in window one, assuming that there are at least two shapes in the selection.
Windows(1).Selection.ShapeRange(2).Fill.ForeColor.RGB = _ RGB(255, 0, 255)
Properties | Adjustments Property | AlternativeText Property | Application Property | AutoShapeType Property | BlackWhiteMode Property | Callout Property | Child Property | ConnectionSiteCount Property | Connector Property | ConnectorFormat Property | Count Property | Creator Property | Diagram Property | DiagramNode Property | Fill Property | GroupItems Property | HasDiagram Property | HasDiagramNode Property | Height Property | HorizontalFlip Property | ID Property | Left Property | Line Property | LockAspectRatio Property | Name Property | Nodes Property | Parent Property | ParentGroup Property | PictureFormat Property | Rotation Property | Shadow Property | TextEffect Property | TextFrame Property | ThreeD Property | Top Property | Type Property | VerticalFlip Property | Vertices Property | Visible Property | Width Property | ZOrderPosition Property
Methods | Align Method | Apply Method | Delete Method | Distribute Method | Duplicate Method | Flip Method | Group Method | IncrementLeft Method | IncrementRotation Method | IncrementTop Method | Item Method | PickUp Method | Regroup Method | RerouteConnections Method | ScaleHeight Method | ScaleWidth Method | Select Method | SetShapesDefaultProperties Method | Ungroup Method | ZOrder Method
Child Objects | Adjustments Object | CalloutFormat Object | ConnectorFormat Object | Diagram Object | DiagramNode Object | FillFormat Object | GroupShapes Object | LineFormat Object | PictureFormat Object | ShadowFormat Object | Shape Object | ShapeNodes Object | TextEffectFormat Object | TextFrame Object | ThreeDFormat Object