Partager via


Shapes Interface

A collection of Shape objects that represent all the shapes in a document or all the shapes in all the headers and footers in a document.

Namespace:  Microsoft.Office.Interop.Word
Assembly:  Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)

Syntax

'Declaration
<GuidAttribute("0002099F-0000-0000-C000-000000000046")> _
Public Interface Shapes _
    Inherits IEnumerable
'Usage
Dim instance As Shapes
[GuidAttribute("0002099F-0000-0000-C000-000000000046")]
public interface Shapes : IEnumerable

Remarks

Each Shape object represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.

Note If you want to work with a subset of the shapes on a document— for example, to do something to only the AutoShapes on the document or to only the selected shapes— you must construct a ShapeRange collection that contains the shapes you want to work with.

Use the Shapes property to return the Shapes collection.

Note If you want to do something (like delete or set a property) to all the shapes on a document at the same time, use the Range method to create a ShapeRange object that contains all the shapes in the Shapes collection, and then apply the appropriate property or method to the ShapeRange object.

Use one of the following methods of the Shapes collection: AddCallout, AddCurve, AddLabel, AddLine, AddOLEControl, AddOLEObject, AddPolyline, AddShape, AddTextbox, AddTextEffect, or BuildFreeform to add a shape to a document and return a Shape object that represents the newly created shape.

Use Shapes(index), where index is the name or the index number, to return a single Shape object.

Each shape is assigned a default name when it is created. For example, if you add three different shapes to a document, they might be named "Rectangle 2," "TextBox 3," and "Oval 4." To give a shape a more meaningful name, set the Name property.

The Shapes collection does not include InlineShape objects. InlineShape objects are treated like characters and are positioned as characters within a line of text. Shape objects are anchored to a range of text but are free-floating and can be positioned anywhere on the page. You can use the ConvertToInlineShape method and the ConvertToShape method to convert shapes from one type to the other. You can convert only pictures, OLE objects, and ActiveX controls to inline shapes.

The Count property for this collection in a document returns the number of items in the main story only. To count the shapes in all the headers and footers, use the Shapes collection with any HeaderFooter object.

See Also

Reference

Shapes Members

Microsoft.Office.Interop.Word Namespace