Shape 对象 (Word)Shape object (Word)

代表绘图层中的对象,例如自选图形、任意多边形、OLE 对象、ActiveX 控件或图片。Represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, ActiveX control, or picture. Shape对象是**Shapes** 集合的成员, 其中包括文档的主要部分或文档的所有页眉和页脚中的所有形状。The Shape object is a member of the Shapes collection, which includes all the shapes in the main story of a document or in all the headers and footers of a document.

备注Remarks

形状总是附加到某个锚定范围。A shape is always attached to an anchoring range. 您可以将形状放置在包含锁定标记的页面上的任何位置。You can position the shape anywhere on the page that contains the anchor.

有三个代表形状的对象: shapes集合, 该集合代表文档中的所有形状;表示文档中的形状的指定子集的**ShapeRange** 对象 (例如, shaperange对象可以代表文档中的第一和第四个形状, 也可以代表文档中的所有选定形状);和Shape对象, 该对象代表文档中的单个形状。There are three objects that represent shapes: the Shapes collection, which represents all the shapes on a document; the ShapeRange object, 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.

使用形状(索引), 其中_索引_是名称或索引号, 返回单个Shape对象。Use Shapes (index), where index is the name or the index number, to return a single Shape object. 下面的示例水平翻转活动文档中的第一个形状。The following example horizontally flips shape one on the active document.

ActiveDocument.Shapes(1).Flip msoFlipHorizontal

下面的示例水平翻转活动文档中名为 "Rectangle 1" 的形状。The following example horizontally flips the shape named Rectangle 1 on the active document.

ActiveDocument.Shapes("Rectangle 1").Flip msoFlipHorizontal

每个形状在被创建时即获得一个默认名称。Each shape is assigned a default name when it is created. 例如,如果在文档中添加三个不同形状,其名称可能是“矩形 2”、“文本框 3”和“椭圆 4”。For example, if you add three different shapes to a document, they might be named Rectangle 2, TextBox 3, and Oval 4. 要使形状的名称更有意义,请设置 Name 属性。To give a shape a more meaningful name, set the Name property.

使用ShapeRange (index) (其中_index_是名称或索引号) 可返回一个shape对象, 该对象表示所选内容中的形状。Use ShapeRange (index), where index is the name or the index number, to return a Shape object that represents a shape within a selection. 假定所选内容包含至少一个形状,则以下示例为所选内容中的第一个形状设置填充效果。The following example sets the fill for the first shape in the selection, assuming that the selection contains at least one shape.

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

假定所选内容至少包含一个形状,则以下示例为该区域的所有形状设置填充效果。The following example sets the fill for all the shapes in the selection, assuming that the selection contains at least one shape.

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

要将 Shape 对象添加到指定文档的形状集合,并返回一个代表新建形状的 Shape 对象,可使用 Shapes 集合的下列方法之一:AddCalloutAddCurveAddLabelAddLineAddOleControlAddOleObjectAddPolylineAddShapeAddTextboxAddTextEffectBuildFreeFormTo add a Shape object to the collection of shapes for the specified document and return a Shape object that represents the newly created shape, use one of the following methods of the Shapes collection: AddCallout, AddCurve, AddLabel, AddLine, AddOleControl, AddOleObject, AddPolyline, AddShape, AddTextbox, AddTextEffect, or BuildFreeForm. 以下示例向活动文档添加一个矩形。The following example adds a rectangle to the active document.

ActiveDocument.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 200

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

每个 Shape 对象都锁定到某个文本范围。Every Shape object is anchored to a range of text. 将某个形状锁定到包含锁定范围的第一段的开头。A shape is anchored to the beginning of the first paragraph that contains the anchoring range. 该形状总是与其锁定标记在同一页上。The shape will always remain on the same page as its anchor.

您可以通过将ShowObjectAnchors属性设置为True来查看锚点本身。You can view the anchor itself by setting the ShowObjectAnchors property to True. 形状的 TopLeft 属性决定其垂直和水平位置。The shape's Top and Left properties determine its vertical and horizontal positions. 形状的 RelativeHorizontalPositionRelativeVerticalPosition 属性则决定是从锚定段落、包含锚定段落的列、边距还是页边来测量位置。The shape's RelativeHorizontalPosition and RelativeVerticalPosition properties determine whether the position is measured from the anchoring paragraph, the column that contains the anchoring paragraph, the margin, or the edge of the page.

如果形状的 LockAnchor 属性设置为 True 时,不能在页面上从其位置拖动锚点。If the LockAnchor property for the shape is set to True, you cannot drag the anchor from its position on the page.

使用Fill属性返回FillFormat对象, 该对象包含用于设置闭合形状的填充格式的所有属性和方法。Use the Fill property to return the FillFormat object, which contains all the properties and methods for formatting the fill of a closed shape.

Shadow 属性会返回 ShadowFormat 对象,该对象可用于设置阴影的格式。The Shadow property returns the ShadowFormat object, which you use to format a shadow.

使用 Line 属性可返回 LineFormat 对象,该对象包含用于设置直线和箭头的格式的属性和方法。Use the Line property to return the LineFormat object, which contains properties and methods for formatting lines and arrows.

TextEffect 属性会返回 TextEffectFormat 对象,该对象可用于设置艺术字的格式。The TextEffect property returns the TextEffectFormat object, which you use to format WordArt.

Callout 属性会返回 CalloutFormat 对象,该对象可用于设置线形标注的格式。The Callout property returns the CalloutFormat object, which you use to format line callouts.

WrapFormat 属性会返回 WrapFormat 对象,该对象可用于定义文字环绕形状的方式。The WrapFormat property returns the WrapFormat object, which you use to define how text wraps around shapes.

ThreeD属性返回ThreeDFormat对象, 该对象用于创建3d 形状。The ThreeD property returns the ThreeDFormat object, which you use to create 3D shapes.

可以使用 PickUpApply 方法将格式设置从一个形状转移到另一个形状。You can use the PickUp and Apply methods to transfer formatting from one shape to another.

使用Shape对象的SetShapesDefaultProperties方法设置文档的默认形状的格式。Use the SetShapesDefaultProperties method for a Shape object to set the formatting for the default shape for the document. 新形状将继承默认形状的许多属性。New shapes inherit many of their attributes from the default shape.

使用Type属性可指定形状的类型: 任意多边形、自选图形、OLE 对象、标注或链接图片, 例如。Use the Type property to specify the type of shape: freeform, AutoShape, OLE object, callout, or linked picture, for example. 使用AutoShapeType属性可以指定自选图形的类型: 椭圆形、矩形或球标, 例如。Use the AutoShapeType property to specify the type of AutoShape: oval, rectangle, or balloon, for example.

使用 宽度高度 属性来指定形状的大小。Use the Width and Height properties to specify the size of the shape.

TextFrame属性返回TextFrame对象, 该对象包含用于将文本附加到形状和链接文本框之间的文本的所有属性和方法。The TextFrame property returns the TextFrame object, which contains all the properties and methods for attaching text to shapes and linking the text between text frames.

Shape 对象锁定到某一文本范围,但可以自由浮动,并且可以放置在页面上的任何位置。Shape objects are anchored to a range of text but are free-floating and can be positioned anywhere on the page. InlineShape 对象被视为字符,并作为字符置于文本行中。InlineShape objects are treated like characters and are positioned as characters within a line of text. 可以使用 ConvertToInlineShape 方法和 ConvertToShape 方法将形状从一种类型转换到另一种类型。You can use the ConvertToInlineShape method and the ConvertToShape method to convert shapes from one type to the other. 只能将图片、OLE 对象和 ActiveX 控件转换为内嵌形状。You can convert only pictures, OLE objects, and ActiveX controls to inline shapes.

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