ShapeRange Collection Object

Description

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.

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 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 the active document.

ActiveDocument.Shapes.Range(Array(1, 3)).Fill.Patterned msoPatternHorizontalBrick
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
myRange.ShapeRange.Select
Aligning, Distributing, and Grouping Shapes in a ShapeRange Object

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

Use the Group, Regroup , and UnGroup methods 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.

Remarks

The recorder always uses the ShapeRange property when recording shapes.

A ShapeRange object doesn't include InlineShape objects.

Properties

Adjustments property, Anchor property, Application property, AutoShapeType property, Callout property, Count property, Creator property, Fill property, GroupItems property, Height property, HorizontalFlip property, Hyperlink property, Left property, Line property, LockAnchor property, LockAspectRatio property, Name property, Nodes property, Parent 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, 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.

See Also

InlineShape object, Shape object, Shapes collection object.