Use a Word VBA Macro to Position an Image in the Top-Right Corner
Question details
Create a Word VBA macro that positions a selected image at the top-right of the page, behind text.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A user wants to position an image in the document body or header using a macro.
- Observed behavior
- The image should be aligned to the page's top-right corner, appear behind text, and remain positioned relative to the page.
Open the document in a desktop version of Microsoft Word that supports VBA, and select the image you want to position. If the image is in a header, double-click the header area before selecting it.
Run a VBA macro to align the selected image to the page
Use this macro for a selected inline or floating image in the document body or a header.
The macro converts an inline image to a floating shape if needed, places it behind text, and aligns it relative to the page.
In Word, press Alt+F11 or select Developer > Visual Basic. In the VBA editor, select Insert > Module.
Paste this code into the module: Sub PositionImageTopRight() Dim img As Shape Select Case Selection.Type Case wdSelectionInlineShape Set img = Selection.InlineShapes(1).ConvertToShape Case wdSelectionShape Set img = Selection.ShapeRange(1) Case Else MsgBox "Select an image first." Exit Sub End Select With img .WrapFormat.Type = wdWrapBehind .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage .RelativeVerticalPosition = wdRelativeVerticalPositionPage .Left = wdShapeRight .Top = wdShapeTop End With End Sub
Return to the document, select the image, and choose Developer > Macros. Select PositionImageTopRight and click Run.
With the resulting image selected, open Layout Options and choose Fix position on page if available. Check the result after editing the surrounding text.

Work with Word documents and images in WPS Writer
WPS Writer is a free, lightweight Office alternative with a familiar interface and support for Word documents. Open an existing document and use its picture-layout tools to arrange images without relying on this Word-specific macro.

Frequently Asked Questions
Can the macro position an inline image?
Yes. Select the inline image before running PositionImageTopRight. The macro converts it to a floating shape so it can be placed behind text and aligned to the page.
Can I use the macro on an image in a header?
Yes. Double-click the header, select its image, and run the macro from Developer > Macros. The image may appear on every page that uses that header.
Why can the image still move to another page?
A floating image is attached to an anchor in the document. If that anchor moves to another page, the image can move with it. Select the image and check Layout Options > Fix position on page if available.
How do I keep the macro for future use?
Use File > Save As and select Word Macro-Enabled Document (.docm) to save the VBA code with the document. Run macros only when you trust their source.




