VBA - Shapes
ShapeRange
Represents a set of shapes in a document.
This could be just 1 shape or 2 or more shapes
Most operations you can do with a Shape object you can also do with a ShapeRange object when it contains only 1 shape.
Text Boxes
For adding textboxes refer to [Pages > VBA Code > Text Boxes]
Deleting Shapes
For some reason (msoPicture) objects can only be removed from headers and footers if the header and footer is activated.
This line of code will not work
Adding Shapes
Anchor - Optional Variant. A Range object that represents the text to which the AutoShape is bound. If Anchor is specified, the anchor is positioned at the beginning of the first paragraph in the anchoring range. If this argument is omitted, the anchoring range is selected automatically and the AutoShape is positioned relative to the top and left edges of the page.
BeginX - Single. The horizontal position, measured in points, of the line's starting point, relative to the anchor.
BeginY - Single. The vertical position, measured in points, of the line's starting point, relative to the anchor.
EndX - Single. The horizontal position, measured in points, of the line's end point, relative to the anchor.
EndY - Single. The vertical position, measured in points, of the line's end point, relative to the anchor.
FileName - String. The path and file name of the picture.
LinkToFile - Variant. True to link the picture to the file from which it was created. False to make the picture an independent copy of the file. The default value is False.
SaveWithDocument - Variant. True to save the linked picture with the document. The default value is False.
Range - Variant. The location where the picture will be placed in the text. If the range isn't collapsed, the picture replaces the range; otherwise, the picture is inserted. If this argument is omitted, the picture is placed automatically.
Changing the Type
Returning a Shape
It is often simpler to use Item when you just have a single item
Returning Several Shapes
You can use VBA.Array to construct a list
ActiveDocument.Shapes.Range(Array("shaperange1","shaperange2"))
Change the fill color of the first shape in the selection
This is not boolean but integer
This is not boolean but integer
Shapes WrapFormat
This example adds an oval to the active document and specifies that the document text wrap around the left and right sides of the square that circumscribes the oval. The example sets a 0.1-inch margin between the document text and the top, bottom, left side, and right side of the square.
Shapes LinkFormat Object
What is a LinkFormat Object ?
Represents the linking characteristics for an OLE object or picture.
Properties
| AutoUpdate | True if the links is updated automatically when the container file is opened. |
| Locked | True is the link is locked to prevent automatic updating. This can only be used on Shapes that are Inline. |
| SavePictureWithDocument | True if the specified picture is saved with the document |
| SourceFullName | Returns or sets the path and name of the source file for the specified linked OLE object, picture, or field. Read/write String. |
| SourceName | Returns the name of the source file for the specified linked OLE object, picture, or field. Read-only String. |
| SourcePath | Returns the path of the source file for the specified linked OLE object, picture, or field. Read-only String. |
| Type |
Methods
| BreakLink | Breaks the link between the source file and the specified OLE object, picture, or linked field. |
| Update | Updates the link |
SourceFullName Property
This example sets MyExcel.xls as the source file for shape one on the active document and specifies that the OLE object be updated automatically.
Using this property is equivalent to using in sequence the SourcePath, PathSeparator and SourceName properties.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext