Share via


PowerPoint) (Shapes.Range 方法

會傳回 ShapeRange 物件,表示 Shapes 集合中圖案的子集合。

語法

運算式範圍 (索引)

expression 代表 Shapes 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Index 選用 Variant 是要包含在範圍中個別的圖形。 可以是圖案的指定之圖案的索引編號的 整數 、 指定,名稱的 字串 或包含整數或字串陣列。 如果省略此引數,則 Range 方法會傳回指定集合中的所有物件。

傳回值

ShapeRange

註解

雖然您可以使用 Range 方法傳回圖案或投影片的任何數字,它會更容易使用 Item 方法,如果您只想要傳回之集合中的單一成員。 例如, Shapes(1)Shapes.Range(1) 簡單,而且 Slides(2)Slides.Range(2) 簡單。

若要指定 索引 的整數或字串陣列,您可以使用 Array 函數。 例如,下列指令會傳回 name 所指定的兩個圖形。

Dim myArray() As Variant, myRange As Object myArray = Array("Oval 4", "Rectangle 5") Set myRange = ActivePresentation.Slides(1).Shapes.Range(myArray)

範例

這個範例會設定 myDocument 上第一個圖案及第三個圖案的填滿圖樣。

Set myDocument = ActivePresentation.Slides(1)

myDocument.Shapes.Range(Array(1, 3)).Fill _
    .Patterned msoPatternHorizontalBrick

本範例會為第一張投影片上名為 Oval 4 和 Rectangle 5 的圖案設定填滿圖樣。

Dim myArray() As Variant, myRange As Object

myArray = Array("Oval 4", "Rectangle 5")

Set myRange = ActivePresentation.Slides(1).Shapes.Range(myArray)

myRange.Fill.Patterned msoPatternHorizontalBrick

本範例會為第一張投影片上的所有圖案設定填滿圖樣。

ActivePresentation.Slides(1).Shapes.Range.Fill _
    .Patterned Pattern:=msoPatternHorizontalBrick

本範例會為第一張投影片上的第一個圖案設定填滿圖樣。

Set myDocument = ActivePresentation.Slides(1)

Set myRange = myDocument.Shapes.Range(1)

myRange.Fill.Patterned msoPatternHorizontalBrick

本範例會建立一個包含第一張投影片上所有快取圖案的陣列、使用該陣列來定義圖案範圍,然後水平均分該範圍中的所有圖案。

With myDocument.Shapes

    numShapes = .Count



    'Continues if there are shapes on the slide

    If numShapes > 1 Then

        numAutoShapes = 0

        ReDim autoShpArray(1 To numShapes)

        For i = 1 To numShapes



            'Counts the number of AutoShapes on the Slide

            If .Item(i).Type = msoAutoShape Then

                numAutoShapes = numAutoShapes + 1

                autoShpArray(numAutoShapes) = .Item(i).Name

            End If

        Next



        'Adds AutoShapes to ShapeRange

        If numAutoShapes > 1 Then

            ReDim Preserve autoShpArray(1 To numAutoShapes)

            Set asRange = .Range(autoShpArray)

            asRange.Distribute msoDistributeHorizontally, False

        End If

    End If

End With


另請參閱

Shapes 物件

支援和意見反應

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