Shape 对象 (PowerPoint)Shape object (PowerPoint)

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



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

有关如何使用单个形状或一次使用多个形状的概述, 请参阅处理形状 (图形对象)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 an existing shape on a slide, indexed by name or number.

  • 返回幻灯片上新建的形状。Return a newly created shape on a slide.

  • 返回选定范围中的形状。Return a shape within the selection.

  • 返回幻灯片上的幻灯片标题和其他占位符。Return the slide title and other placeholders on a slide.

  • 返回与连接符的端点相连的形状。Return the shapes attached to the ends of a connector.

  • 返回演示文稿的默认形状。Return the default shape for a presentation.

  • 返回新建的任意多边形。Return a newly created freeform.

  • 返回组合内的单个形状。Return a single shape from within a group.

  • 返回新组合的一组形状。Return a newly formed group of shapes.


使用Shapes (index) (其中_index_是形状名称或索引号) 可返回一个代表幻灯片上的形状的shape对象。Use Shapes (index), where index is the shape name or the index number, to return a Shape object that represents a shape on a slide. 下例将 myDocument 中的形状一和名为“Rectangle 1”的形状进行水平翻转。The following example horizontally flips shape one and the shape named Rectangle 1 on myDocument.

Set myDocument = ActivePresentation.Slides(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 = ActivePresentation.Slides(1)

With myDocument.Shapes.AddShape(Type:=msoShapeRectangle, _

        Top:=144, Left:=144, Width:=72, Height:=72)

    .Name = "Red Square"

    .Fill.ForeColor.RGB = RGB(255, 0, 0)

    .Line.DashStyle = msoLineDashDot

End With

若要将形状添加到幻灯片并返回一个shape对象, 该对象表示新创建的形状, 请使用Shapes集合的下列方法之一: Add3DModelAddCalloutAddConnectorAddCurveAddLabelAddLineAddMediaObjectAddOLEObjectAddPictureAddPlaceholderAddPolylineAddShapeAddTableAddTextboxAddTextEffectAddTitleTo add a shape to a slide and return a Shape object that represents the newly created shape, use one of the following methods of the Shapes collection: Add3DModel, AddCallout, AddConnector, AddCurve, AddLabel, AddLine, AddMediaObject, AddOLEObject, AddPicture, AddPlaceholder, AddPolyline, AddShape, AddTable, AddTextbox, AddTextEffect, AddTitle.

使用所选内容。 ShapeRange (index) (其中_index_是形状名称或索引号) 可返回一个代表选定区域中的形状的shape对象。Use Selection.ShapeRange (index), where index is the shape name or the index number, to return a Shape object that represents a shape within the selection. 下例设置了活动窗口内选定区域中的第一个形状的填充格式,假定至少选定了一个形状。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)

使用 Shapes.Title 返回代表幻灯片标题的 Shape 对象。Use Shapes.Title to return a Shape object that represents an existing slide title. 使用 Shapes.AddTitle 在无标题的幻灯片中添加标题并返回代表新建标题的 Shape 对象。Use Shapes.AddTitle to add a title to a slide that doesn't already have one and return a Shape object that represents the newly created title. 使用形状。占位符(索引), 其中_索引_是占位符的索引号, 返回一个代表占位符的Shape对象。Use Shapes.Placeholders (index), where index is the placeholder's index number, to return a Shape object that represents a placeholder. 如果没有改变过幻灯片上形状的排列顺序,则以下三个语句是等效的(假定第一张幻灯片有标题)。If you have not changed the layering order of the shapes on a slide, the following three statements are equivalent, assuming that slide one has a title.

ActivePresentation.Slides(1).Shapes.Title _

    .TextFrame.TextRange.Font.Italic = True

ActivePresentation.Slides(1).Shapes.Placeholders(1) _

    .TextFrame.TextRange.Font.Italic = True

ActivePresentation.Slides(1).Shapes(1).TextFrame _

    .TextRange.Font.Italic = True

若要返回表示连接符所连接形状之一的Shape对象, 请使用**BeginConnectedShape** 或**EndConnectedShape** 属性。To return a Shape object that represents one of the shapes attached by a connector, use the BeginConnectedShape or EndConnectedShape property.

若要返回一个shape对象, 该对象代表演示文稿的默认形状, 请使用**DefaultShape** 属性。To return a Shape object that represents the default shape for a presentation, use the DefaultShape property.

使用**BuildFreeform** 和**AddNodes** 方法可定义新任意多边形的几何形状, 使用**ConvertToShape** 方法可创建任意多边形并返回代表该任意多边形的Shape对象。Use 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.

使用GroupItems (index) (其中_index_是形状名称或组中的索引号) 可返回一个shape对象, 该对象表示组合形状中的单个形状。Use GroupItems (index), where index is the shape name or the index number within the group, to return a Shape object that represents a single shape in a grouped shape.

使用 重组 方法组合形状范围并返回单个 Shape 对象表示新组成的组。Use the Group or Regroup method 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 you work with any other shape.



另请参阅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.