Table of contents
Collapse the table of content
Expand the table of content

Shapes.Range Method (Project)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Returns a ShapeRange object that represents a subset of shapes in the Shapes collection.


expression. Range(Index)

expression A variable that represents a Shapes object.


NameRequired/OptionalData TypeDescription
IndexRequiredVariantSpecifies one or more shapes to be included in the range. Can be an integer for the index number of a shape, a string for the name of a shape, or an array that contains either integers or strings.
NameRequired/OptionalData typeDescription

Return value


The range of shapes that are specified by the Index parameter.


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.

Although you can use the Range property to return any number of shapes on a report, it is simpler to use the default Value property to return a single Shape in the collection. For example, Shapes(1) is simpler than Shapes.Range(1).

To specify an array of integers or strings for the Index parameter, you can use the Array function. For example, the following macro selects two shapes that are specified by name.

Sub SelectShapeRange()
    Dim arShapes() As Variant
    Dim oShapeRange As ShapeRange

    arShapes = Array("TextBox 4", "TextBox 5")
    Set oShapeRange = ActiveProject.Reports("Table Tests").Shapes.Range(arShapes)
End Sub


If you create a report that has two text boxes such as in the previous code, the following macro selects the text boxes by index number, and then adds a shadow to each of them.

Sub AddShadow2Shapes()
    Dim oReports As Reports
    Dim oReport As Report
    Dim oShapeRange As ShapeRange
    Dim reportName As String
    Dim arShapes() As Variant

    arShapes = Array(3, 4)

    reportName = "Table Tests"
    Set oReports = ActiveProject.Reports

    If (oReports.IsPresent(reportName)) Then
        ' Make the report the active view.

        Set oReport = oReports(reportName)

        Set oShapeRange = oReport.Shapes.Range(arShapes)

        oShapeRange.Shadow.Type = msoShadow1
    End If
End Sub

See also

Other resources

Shapes ObjectShapeRange Object

© 2018 Microsoft