VBA & Macro Problems

Use a Word VBA Macro to Position an Image in the Top-Right Corner

John WilsonJohn Wilson Nov 25, 2026 869 views

Question details

Create a Word VBA macro that positions a selected image at the top-right of the page, behind text.

Position an Image in the Top-Right Corner with Word VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Word, press Alt+F11 or select Developer > Visual Basic. In the VBA editor, select Insert > Module.

2
Add the macro

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

3
Run the macro

Return to the document, select the image, and choose Developer > Macros. Select PositionImageTopRight and click Run.

4
Check the position setting

With the resulting image selected, open Layout Options and choose Fix position on page if available. Check the result after editing the surrounding text.

Run a VBA macro to align the selected image to the page
Page alignment and anchors: The macro aligns the image relative to its anchor's page; it does not set Word's Fix position on page option. If the anchor moves to another page, the image can move with it. An image placed in a header may repeat on pages that use that header.
Free Microsoft Office alternative

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.

Arrange pictures and text in documents using visual layout toolsOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface to make the transition from Microsoft Office easierWork with documents in a free, lightweight office suite
microsoft office alternative - wps office

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.