ShapeRange Collection Object

Multiple objects
Multiple objects

Represents a shape range, which is a set of shapes on a document. A shape range can contain as few as one shape or as many as all the shapes in the document. You can include whichever shapes you want — chosen from among all the shapes in 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 in a document, all the selected shapes in a document, or all the freeform shapes in a document.

Note  Most operations that you can do with a Shape object, you can also do with a ShapeRange object that contains only one shape. Some operations, when performed on a ShapeRange object that contains more than one shape, will cause an error.

Using the ShapeRange Collection

This section describes how to:

  • Return a set of shapes you specify by name or index number.
  • Return a ShapeRange object within a selection or range.

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 Visual Basic's Array function to construct an array of names or index numbers. The following example sets the fill pattern for shapes one and three on the active document.

ActiveDocument.Shapes.Range(Array(1, 3)).Fill.Patterned _

The following example selects the shapes named "Oval 4" and "Rectangle 5" on the active document.

ActiveDocument.Shapes.Range(Array("Oval 4", "Rectangle 5")).Select

Although you can use the Range method to return any number of shapes, 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 Shapes.Range(1).

Returning a ShapeRange Object Within a Selection or Range

Use Selection.ShapeRange(index), where index is the name or the index number, to return a Shape object that represents a shape within a selection. The following example sets the fill for the first shape in the selection, assuming that the selection contains at least one shape.

Selection.ShapeRange(1).Fill.ForeColor.RGB = RGB(255, 0, 0)

This example selects all the shapes in the first section of the active document.

Set myRange = ActiveDocument.Sections(1).Range

Aligning, Distributing, and Grouping Shapes in a ShapeRange Object

Use the Align , Distribute , or ZOrder method to position a set of shapes relative to each other or relative to the document.

Use the Group , Regroup , or UnGroup method to create and work with a single shape formed from a shape range. The GroupItems property for a Shape object returns the GroupShapes object, which represents all the shapes that were grouped to form one shape.


The recorder always uses the ShapeRange property when recording shapes.

A ShapeRange object doesn't include InlineShape objects.

Properties | Adjustments Property | AlternativeText Property | Anchor Property | Application Property | AutoShapeType Property | Callout Property | CanvasItems Property | Child Property | Count Property | Creator Property | Diagram Property | DiagramNode Property | Fill Property | GroupItems Property | HasDiagram Property | HasDiagramNode Property | Height Property | HorizontalFlip Property | Hyperlink Property | ID Property | LayoutInCell Property | Left Property | Line Property | LockAnchor Property | LockAspectRatio Property | Name Property | Nodes Property | Parent Property | ParentGroup Property | PictureFormat Property | RelativeHorizontalPosition Property | RelativeVerticalPosition Property | Rotation Property | Shadow Property | TextEffect Property | TextFrame Property | ThreeD Property | Top Property | Type Property | VerticalFlip Property | Vertices Property | Visible Property | Width Property | WrapFormat Property | ZOrderPosition Property

Methods | Activate Method | Align Method | Apply Method | CanvasCropBottom Method | CanvasCropLeft Method | CanvasCropRight Method | CanvasCropTop Method | ConvertToFrame Method | ConvertToInlineShape Method | Delete Method | Distribute Method | Duplicate Method | Flip Method | Group Method | IncrementLeft Method | IncrementRotation Method | IncrementTop Method | Item Method | PickUp Method | Regroup Method | ScaleHeight Method | ScaleWidth Method | Select Method | SetShapesDefaultProperties Method | Ungroup Method | ZOrder Method

Parent Objects | Range Object | Selection Object

Child Objects | Adjustments Object | CalloutFormat Object | CanvasShapes Object | Diagram Object | DiagramNode Object | FillFormat Object | GroupShapes Object | Hyperlink Object | LineFormat Object | PictureFormat Object | Range Object | ShadowFormat Object | Shape Object | ShapeNodes Object | TextEffectFormat Object | TextFrame Object | ThreeDFormat Object | WrapFormat Object

See Also | InlineShape Object | Shape Object | Shapes Collection Object