ShapeRange object (Word)

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. 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.

Use 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. 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 is 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).

Use 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 

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.



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.