Share via


Shapes.Range Method

Word Developer Reference

Returns a ShapeRange object that represents the shapes within a range.

Syntax

expression.Range(Index)

expression   Required. A variable that represents a Shapes collection.

Parameters

Name Required/Optional Data Type Description
Index Required Variant Specifies which shapes are to be included in the specified range. Can be an integer that specifies the index number of a shape within the Shapes collection, a string that specifies the name of a shape, or a array that contains integers or strings.

Return Value
ShapeRange

Remarks

A Shape object always appears on the same page as the range it is anchored to.

Bb217195.vs_note(en-us,office.12).gif  Note
Most operations that you can do with a Shape object you can also do with a ShapeRange object that contains a single shape. Some operations, when performed on a ShapeRange object that contains multiple shapes, produce an error.

Example

This example sets the fill foreground color to purple for the first shape in the active document.

Visual Basic for Applications
  Sub ShRange()
    With ActiveDocument.Shapes.Range(1).Fill
        .ForeColor.RGB = RGB(255, 0, 255)
        .Visible = msoTrue
    End With
End Sub

This example applies a shadow to a variable shape in the active document.

Visual Basic for Applications
  Sub ShpRange2(strShpName As String)
    ActiveDocument.Shapes.Range(strShpName).Shadow.Type = msoShadow6
End Sub

To call the preceding subroutine, enter the following code into a standard code module.

Visual Basic for Applications
  Sub CallShpRange2()
    Dim shpArrow As Shape
    Dim strName As String
Set shpArrow = ActiveDocument.Shapes.AddShape(Type:=msoShapeLeftArrow, _
    Left:=200, Top:=400, Width:=50, Height:=75)

shpArrow.Name = "myShape"
strName = shpArrow.Name
ShpRange2 strShpName:=strName

End Sub

This example selects shapes one and three in the active document.

Visual Basic for Applications
  Sub SelectShapeRange()
    ActiveDocument.Shapes.Range(Array(1, 3)).Select
End Sub

This example selects and deletes the shapes in the first shape in the active document. This example assumes that the first shape is a canvas shape.

Visual Basic for Applications
  Sub CanvasShapeRange()
    Dim rngCanvasShapes As Range
    Set rngCanvasShapes = ActiveDocument.Shapes(1).CanvasItems.Range(1)
    rngCanvasShapes.Select
    rngCanvasShapes.Delete
End Sub

See Also