ShapeRange 物件 (Excel)ShapeRange object (Excel)

代表圖案範圍,即文件上的一組圖案。Represents a shape range, which is a set of shapes on a document.

備註Remarks

圖案範圍最少可包含一個圖案,最多可包含文件上所有圖案。A shape range can contain as few as a single shape or as many as all the shapes on the document. 您可以包含您想無論的圖形 — 選擇針對文件上的所有圖案或選取範圍中的所有圖案 — 來建構圖案範圍。You can include whichever shapes you want—chosen from among all the shapes on the document or all the shapes in the selection—to construct a shape range. 例如,您可以建構包含文件的前三個圖案、 所有選取的圖形或文件上的所有手繪多邊形的 ShapeRange 集合。For example, you could construct a ShapeRange collection that contains the first three shapes on a document, all the selected shapes on a document, or all the freeforms on a document.

範例Example

依名稱或索引編號傳回一組您指定的圖案Return a set of shapes that you specify by name or index number

使用**Range** (index),其中_index_是名稱或索引編號的陣列,包含可能是名稱或的圖案的索引編號,可以傳回代表一組文件上的圖案的ShapeRange集合。Use Range (index), where index is the name or index number of the shape or an array that contains either names or index numbers of shapes, to return a ShapeRange collection that represents a set of shapes on a document. 您可以使用 Array 函數建構名稱或索引編號的陣列。You can use the Array function to construct an array of names or index numbers.

下列範例會設定 myDocument 上第一個及第三個圖案的填滿圖樣。The following example sets the fill pattern for shapes one and three on myDocument.

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

下列範例會設定 myDocument 上 Oval 4 及 Rectangle 5 圖案的填滿圖樣。The following example sets the fill pattern for the shapes named Oval 4 and Rectangle 5 on myDocument.

雖然可以使用 Range 屬性傳回任意數目的圖案或投影片,但是,如果只要傳回集合中的單一成員,則使用 Item 方法會比較簡單。Although you can use the Range property to return any number of shapes or slides, it's simpler to use the Item method if you want to return only a single member of the collection. 例如, Shapes(1)是比 Shapes.Range(1)簡單。For example, Shapes(1) is simpler than Shapes.Range(1).

Set myDocument = Worksheets(1) 
Set myRange = myDocument.Shapes.Range(Array("Oval 4", _ 
 "Rectangle 5")) 
myRange.Fill.Patterned msoPatternHorizontalBrick

傳回文件上的所有或部分選取的圖案Return all or some of the selected shapes on a document

使用 Selection 物件的 ShapeRange 屬性可傳回選取範圍中的所有圖案。Use the ShapeRange property of the Selection object to return all the shapes in the selection. 本範例會將填滿前景色彩的第一個視窗中,假設選取範圍中的所有圖形的選取範圍中的至少一個圖形。The following example sets the fill foreground color for all the shapes in the selection in window one, assuming that there's at least one shape in the selection.

Windows(1).Selection.ShapeRange.Fill.ForeColor.RGB = _ 
 RGB(255, 0, 255)

使用_選取項目_。ShapeRange(index),其中_index_是圖案的名稱或索引編號,可以傳回選取範圍內的單一圖案。Use Selection.ShapeRange (index), where index is the shape name or the index number, to return a single shape within the selection. 下列範例會將填滿前景色彩的第二個圖案的選取的圖案集合中第一個視窗,假設中至少有兩個圖形選取範圍中。The following example sets the fill foreground color for shape two in the collection of selected shapes in window one, assuming that there are at least two shapes in the selection.

Windows(1).Selection.ShapeRange(2).Fill.ForeColor.RGB = _ 
 RGB(255, 0, 255)

方法Methods

屬性Properties

另請參閱See also

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.