Shape Object
| Excel Developer Reference |
Remarks
The Shape object is a member of the Shapes collection. The Shapes collection contains all the shapes in a workbook.
Note |
|---|
| 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. If you want to work with several shapes at the same time or with shapes within the selection, use a ShapeRange collection. |
Using the Shape Object
The following sections describes how to:
- Return the shapes attached to the ends of a connector.
- Return a newly created freeform.
- Return a single shape from within a group.
- Return a newly formed group of shapes.
- Return an existing shape.
- Return a shape within the selection.
Returning the Shapes Attached to the Ends of a Connector
To return a Shape object that represents one of the shapes attached by a connector, use the BeginConnectedShape or EndConnectedShape property.
Returning a newly created freeform
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.
Returning a Single Shape from Within a Group
Use GroupItems(
Returning a Newly Formed Group of Shapes
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.
Returning an Existing Shape
Use Shapes(
Returning a Shape Within the Selection
Use Selection.ShapeRange(
Example
The following example horizontally flips shape one and the shape named Rectangle 1 on myDocument.
| Visual Basic for Applications |
|---|
|
Each shape is assigned a default name when you add it to the Shapes collection. To give the shape a more meaningful name, use the Name property. The following example adds a rectangle to myDocument, gives it the name Red Square, and then sets its foreground color and line style.
| Visual Basic for Applications |
|---|
|
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.
| Visual Basic for Applications |
|---|
|
- 3/17/2009
- Chris Carson
Note