Shapes.Range method (Project)
Returns a ShapeRange object that represents a subset of shapes in the Shapes collection.
Syntax
expression.Range (Index)
expression A variable that represents a Shapes object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
Index | Required | Variant | Specifies 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. |
Index | Required | Variant | |
Name | Required/Optional | Data type | Description |
Return value
ShapeRange
The range of shapes that are specified by the Index parameter.
Remarks
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)
oShapeRange.Select
End Sub
Example
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.
oReports(reportName).Apply
Set oReport = oReports(reportName)
Set oShapeRange = oReport.Shapes.Range(arShapes)
oShapeRange.Select
oShapeRange.Shadow.Type = msoShadow1
End If
End Sub
See also
Shapes Object ShapeRange Object
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.