Shape object (Publisher)
Represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, ActiveX control, or picture. The Shape object is a member of the Shapes collection, which includes all the shapes on a page or in a selection.
Note
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).
- The Shape object, which represents a single shape on a document.
If you want to work with several shapes at the same time or with shapes within the selection, use a ShapeRange collection.
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 of the shape.
Use Selection.ShapeRange (index), where index is the name or the index number, to return a Shape object that represents a shape within a selection.
To 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
- AddConnector
- AddCurve
- AddLabel
- AddLine
- AddOLEObject
- AddPolyline
- AddShape
- AddTextBox
- AddTextEffect
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. Use the ShapeRange.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 that you work with any other shape.
Use the AutoShapeType property to specify the type of AutoShape: oval, rectangle, or balloon, for example.
Use the Callout property, which returns the CalloutFormat object, to format line callouts.
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 Line property to return a LineFormat object, which contains properties and methods for formatting lines and arrows.
Use the PickUp and Apply methods to transfer formatting from one shape to another.
Use the SetShapesDefaultProperties method to set the formatting for the default shape for the document. New shapes inherit many of their attributes from the default shape.
Use the Shadow property, which returns the ShadowFormat object, to format a shadow.
Use the TextEffect property, which returns the TextEffectFormat object, to format WordArt.
Use TextFrame and Cell.TextRange properties to return the TextFrame and TextRange objects, respectively, which contain all the properties and methods for inserting and formatting text within shapes and publications and linking the text frames together.
Use the TextWrap property, which returns the WrapFormat object, to define how text wraps around shapes.
Use the ThreeD property, which returns the ThreeDFormat object, to create 3D shapes.
Use the Type property to specify the type of shape: freeform, AutoShape, OLE object, callout, or linked picture, for example.
Use the Width and Height properties to specify the size of the shape.
The following example horizontally flips shape one on the active document.
Sub FlipShape()
ActiveDocument.Pages(1).Shapes(1).Flip FlipCmd:=msoFlipHorizontal
End Sub
The following example horizontally flips the shape named Rectangle 1 on the active document.
Sub FlipShapeByName()
ActiveDocument.Pages(1).Shapes("Rectangle 1") _
.Flip FlipCmd:=msoFlipHorizontal
End Sub
The following example sets the fill for the first shape in the selection, assuming that the selection contains at least one shape.
Sub FillSelectedShape()
Selection.ShapeRange(1).Fill.ForeColor.RGB = RGB(255, 0, 0)
End Sub
The following example sets the fill for all the shapes in the selection, assuming that the selection contains at least one shape.
Sub FillAllSelectedShapes()
Dim shpShape As Shape
For Each
shpShape In Selection.ShapeRange
shpShape.Fill.ForeColor.RGB = RGB(Red:=255, Green:=0, Blue:=0)
Next shpShape
End Sub
The following example adds a rectangle to the active document.
Sub AddNewShape()
ActiveDocument.Pages(1).Shapes.AddShape Type:=msoShapeRectangle, _
Left:=400, Top:=72, Width:=100, Height:=200
End Sub
This example adds three shapes to the active publication, groups the shapes, and sets the fill color for each of the shapes in the group.
Sub WorkWithGroupShapes()
With ActiveDocument.Pages(1).Shapes
.AddShape Type:=msoShapeIsoscelesTriangle, Left:=100, _
Top:=72, Width:=100, Height:=100
.AddShape Type:=msoShapeIsoscelesTriangle, Left:=250, _
Top:=72, Width:=100, Height:=100
.AddShape Type:=msoShapeIsoscelesTriangle, Left:=400, _
Top:=72, Width:=100, Height:=100
.SelectAll
With Selection.ShapeRange
.Group
.GroupItems(1).Fill.ForeColor _
.RGB = RGB(Red:=255, Green:=0, Blue:=0)
.GroupItems(2).Fill.ForeColor _
.RGB = RGB(Red:=0, Green:=255, Blue:=0)
.GroupItems(3).Fill.ForeColor _
.RGB = RGB(Red:=0, Green:=0, Blue:=255)
End With
End With
End Sub
The following example adds a text box to the first page of the active publication, and then adds text to it and formats the text.
Sub CreateNewTextBox()
With ActiveDocument.Pages(1).Shapes.AddTextbox( _
Orientation:=pbTextOrientationHorizontal, Left:=100, _
Top:=100, Width:=200, Height:=100).TextFrame.TextRange
.Text = "This is a textbox."
With .Font
.Name = "Stencil"
.Bold = msoTrue
.Size = 30
End With
End With
End Sub
- AddToCatalogMergeArea
- Apply
- Copy
- Cut
- Delete
- Duplicate
- Flip
- GetHeight
- GetLeft
- GetTop
- GetWidth
- IncrementLeft
- IncrementRotation
- IncrementTop
- MoveIntoTextFlow
- MoveOutOfTextFlow
- MoveToPage
- PickUp
- RemoveCatalogMergeArea
- RemoveFromCatalogMergeArea
- RerouteConnections
- SaveAsBuildingBlock
- SaveAsPicture
- ScaleHeight
- ScaleWidth
- Select
- SetCaption
- SetShapesDefaultProperties
- Ungroup
- ZOrder
- Adjustments
- AlternativeText
- Application
- AutoShapeType
- BlackWhiteMode
- BorderArt
- Callout
- CatalogMergeItems
- ConnectionSiteCount
- Connector
- ConnectorFormat
- Fill
- Glow
- GroupItems
- HasTable
- HasTextFrame
- Height
- HorizontalFlip
- Hyperlink
- ID
- InlineAlignment
- InlineTextRange
- IsExcess
- IsGroupMember
- IsInline
- Left
- Line
- LinkFormat
- LockAspectRatio
- Name
- Nodes
- OLEFormat
- Parent
- ParentGroupShape
- PictureFormat
- Reflection
- Rotation
- Shadow
- SoftEdge
- Table
- Tags
- TextEffect
- TextFrame
- TextWrap
- ThreeD
- Top
- Type
- VerticalFlip
- Vertices
- WebCheckBox
- WebCommandButton
- WebListBox
- WebNavigationBarSetName
- WebOptionButton
- WebTextBox
- Width
- Wizard
- WizardTag
- WizardTagInstance
- ZOrderPosition
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.