共用方式為


Shapes.Range 方法 (專案)

回傳一個 ShapeRange 物件,代表 Shapes 集合中的一部分形狀。

語法

表情範圍 (指數)

expression 代表 Shapes 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Index 必要 Variant 指定一個或多個形狀納入範圍。 可以是形狀索引號的整數、形狀名稱的字串,或包含整數或字串的陣列。
Index 必要 Variant
名稱 必要/選用 資料類型 描述

傳回值

ShapeRange

索引 參數指定的形狀範圍。

註解

注意事項

您可以運用的 Shape 物件的大部分作業也運用包含單一圖案的 ShapeRange 物件。 當在含有多個圖形的 ShapeRange 物件上執行某些作業會產生錯誤。

雖然你可以使用 Range 屬性在報表中回傳任意數量的形狀,但使用預設的 Value 屬性回傳集合中的單一 形狀 會更簡單。 例如, Shapes(1)是比 Shapes.Range(1)簡單。

若要指定 索引參數的 整數或字串陣列,可以使用 Array 函數。 例如,以下巨集選取兩個以名稱指定的形狀。

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

範例

如果你建立一個報告,像前面的程式碼中有兩個文字框,以下的巨集會依索引號選擇文字框,然後為每個框加上陰影。

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

另請參閱

形狀 物件形狀範圍 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應