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.

使用Shapes (index),其中_index_是名稱或索引編號,可以傳回單一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. 例如,如果您將三個不同的圖案加入至文件,它們的名稱可能就是 Rectangle 2、TextBox 3 及 Oval 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.

使用 群組Regroup 方法來群組的圖案範圍並傳回代表新組成的群組的單一 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屬性設定為TrueYou can view the anchor itself by setting the ShowObjectAnchors property to True. 圖形的上方左邊屬性決定其垂直和水平位置。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.

Use the Fill property to return the FillFormat object, which contains all the properties and methods for formatting the fill of a closed shape.Use the Fill property to return the FillFormat object, which contains all the properties and methods for formatting the fill of a closed shape.

The Shadow property returns the ShadowFormat object, which you use to format a shadow.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.

The TextEffect property returns the TextEffectFormat object, which you use to format WordArt.The TextEffect property returns the TextEffectFormat object, which you use to format WordArt.

The Callout property returns the CalloutFormat object, which you use to format line callouts.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.

You can use the PickUp and Apply methods to transfer formatting from one shape to another.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屬性來指定 AutoShape 的類型: 橢圓、 矩形或汽球,例如。Use the AutoShapeType property to specify the type of AutoShape: oval, rectangle, or balloon, for example.

使用 WidthHeight 屬性可指定圖案的大小。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.