ShapeRange 对象 (PowerPoint)ShapeRange object (PowerPoint)

代表一个形状范围,即某个文档中的一组形状。Represents a shape range, which is a set of shapes on a document. 形状范围可以只包含文档中的一个形状,也可以包含该文档中的所有形状。A shape range can contain as few as a single shape or as many as all the shapes on the document.

说明Remarks

您可以包含所需的任何形状 (从文档中的所有形状或选定内容中的所有形状中选择) 来构建一个形状范围。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.

有关如何使用单个形状或一次使用多个形状的概述, 请参阅处理形状 (图形对象)For an overview of how to work with either a single shape or with more than one shape at a time, see Work with shapes (drawing objects).

以下示例说明如何执行下列操作:The following examples describe how to:

  • 返回通过名称或索引号指定的一组形状。Return a set of shapes that you specify by name or index number.

  • 返回文档中全部或部分选定的形状。Return all or some of the selected shapes on a document.

示例Example

使用shapes。 Range (index), 其中_index_是形状或包含形状的名称或索引号的数组的名称或索引号, 返回一个表示文档中的一组形状的ShapeRange集合。Use Shapes.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 = ActivePresentation.Slides(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.

Set myDocument = ActivePresentation.Slides(1)

Set myRange = myDocument.Shapes _

    .Range(Array("Oval 4", "Rectangle 5"))

myRange.Fill.Patterned msoPatternHorizontalBrick

虽然您可以使用**Range** 方法返回任意数量的形状或幻灯片, 但如果只想返回集合中的单个成员, 则使用**Item** 方法更为简单。Although you can use the Range method to return any number of shapes or slides, it is 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).

使用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.