Shape 对象 (Excel)Shape object (Excel)

代表绘图层中的对象,例如自选图形、任意多边形、OLE 对象或图片。Represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.

注释Remarks

Shape 对象是 Shapes 集合的成员。The Shape object is a member of the Shapes collection. Shapes 集合包含某个工作簿中的所有形状。The Shapes collection contains all the shapes in a workbook.

备注

有三个代表形状的对象: shapes集合, 该集合代表工作簿中的所有形状;shaperange 集合, 代表工作簿中的形状的指定子集 (例如, ShapeRange对象可以代表工作簿中的第一和第四个形状, 也可以代表工作簿中的所有选定形状);和Shape对象, 该对象代表工作表上的单个形状。There are three objects that represent shapes: the Shapes collection, which represents all the shapes on a workbook; the ShapeRange collection, which represents a specified subset of the shapes on a workbook (for example, a ShapeRange object could represent shapes one and four in the workbook, or it could represent all the selected shapes in the workbook); and the Shape object, which represents a single shape on a worksheet. 如果您需要同时处理几个形状,或处理选定区域中的多个形状,请使用 ShapeRange 集合。If you want to work with several shapes at the same time or with shapes within the selection, use a ShapeRange collection.

若要返回 .。。To return... Use...Use...
一个代表连接符所连接的形状之一的Shape对象A Shape object that represents one of the shapes attached by a connector ConnectorFormat对象的**BeginConnectedShape** 或**EndConnectedShape** 属性。The BeginConnectedShape or EndConnectedShape property of the ConnectorFormat object.
新创建的任意多边形A newly created freeform BuildFreeform 和**AddNodes** 方法, 用于定义新任意多边形的几何形状, 并使用**ConvertToShape** 方法创建任意多边形并返回代表该形状的 Shape对象。The BuildFreeform and AddNodes methods to define the geometry of a new freeform, and use the ConvertToShape method to create the freeform and return the Shape object that represents it.
一个代表组合形状中的单个形状的shape对象A Shape object that represents a single shape in a grouped shape GroupItems(index), 其中_index_是形状名称或组中的索引号。GroupItems (index), where index is the shape name or the index number within the group.
新组成的形状组A newly formed group of shapes ShapeRange对象的**编组** 或**重组** 方法, 用于对一系列形状进行分组, 并返回单个Shape对象, 该对象表示新形成的组。The Group or Regroup method of the ShapeRange object to group a range of shapes and return a single Shape object that represents the newly formed group. 形成一个组后, 您可以像处理任何其他形状一样使用该组合。After a group has been formed, you can work with the group the same way that you work with any other shape.
一个代表现有形状的shape对象A Shape object that represents an existing shape 形状(index), 其中_index_是形状名称或索引号。Shapes (index), where index is the shape name or the index number.
一个代表所选内容中的形状的shape对象A Shape object that represents a shape within the selection 选择ShapeRange(index), 其中_index_是形状名称或索引号。Selection.ShapeRange (index), where index is the shape name or the index number.

示例Example

下例将 myDocument 中的形状一和名为“Rectangle 1”的形状进行水平翻转。The following example horizontally flips shape one and the shape named Rectangle 1 on myDocument.

Set myDocument = Worksheets(1) 
myDocument.Shapes(1).Flip msoFlipHorizontal 
myDocument.Shapes("Rectangle 1").Flip msoFlipHorizontal

每个添加到 Shapes 集合的形状将被分配一个默认名称。Each shape is assigned a default name when you add it to the Shapes collection. 若要赋予该形状一个更有意义的名称,请使用 Name 属性。To give the shape a more meaningful name, use the Name property. 下面的示例向_myDocument_中添加一个矩形, 并将其命名为红色方形, 然后设置其前景色和线条样式。The following example adds a rectangle to myDocument, gives it the name Red Square, and then sets its foreground color and line style.

Set myDocument = Worksheets(1) 
With myDocument.Shapes.AddShape(msoShapeRectangle, _ 
 144, 144, 72, 72) 
 .Name = "Red Square" 
 .Fill.ForeColor.RGB = RGB(255, 0, 0) 
 .Line.DashStyle = msoLineDashDot 
End With

下例设置了活动窗口内选定区域中的第一个形状的填充格式,假定至少选定了一个形状。The following example sets the fill for the first shape in the selection in the active window, assuming that there's at least one shape in the selection.

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

方法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.