Use Word VBA to Find and Reorder a Header Image
Question details
Find a specific overlapping image in a Word header by its alternative text and change its stacking order with VBA.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A header contains overlapping images, and the user wants VBA to identify one image and bring it forward or send it backward.
- Observed behavior
- Code that worked after the images were moved onto the page did not work while they were in the header.
Open the header and give the target image a distinctive alternative text description, such as “Logo 1.” Make sure the image is a floating shape rather than an inline picture, because the macro uses the Shapes collection.
Find the header image by alternative text and change its order
Use this macro when the target is a floating image in a Word header.
Header shapes are accessed through a section's header, not necessarily through the main document's Shapes collection. The macro checks existing headers in each section and stops at the first matching shape.
Double-click the header, select the target image, and right-click it. Choose Edit Alt Text and enter a distinctive description such as “Logo 1.”
With the image selected, open Layout Options or Wrap Text. If it is set to In Line with Text, choose a floating layout such as Square so it can be accessed as a Shape.
Open the Visual Basic Editor from Word's Developer tab, choose Insert > Module, and paste this code: Sub ReorderHeaderImage() Dim sec As Section Dim hdr As HeaderFooter Dim shp As Shape For Each sec In ActiveDocument.Sections For Each hdr In sec.Headers If hdr.Exists Then For Each shp In hdr.Shapes If StrComp(Trim$(shp.AlternativeText), "Logo 1", vbTextCompare) = 0 Then shp.ZOrder msoBringToFront MsgBox "Header image brought to front." Exit Sub End If Next shp End If Next hdr Next sec MsgBox "No matching header image was found." End Sub
In Word, open Developer > Macros, select ReorderHeaderImage, and click Run. Check the header to confirm the image is in front. To send it behind other shapes instead, replace msoBringToFront with msoSendToBack and run the macro again.

Arrange header images with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for easier document migration. In WPS Writer, you can arrange overlapping header images manually; compatibility with Word-specific VBA macros may vary.

Frequently Asked Questions
Why doesn't ActiveDocument.Shapes find my header image?
A header has its own Shapes collection. Loop through ActiveDocument.Sections and each section's Headers, then search hdr.Shapes for the image.
How do I send the image behind the others?
In the macro, replace shp.ZOrder msoBringToFront with shp.ZOrder msoSendToBack, then run it from Developer > Macros.
What if the macro reports that it cannot find the image?
Open the header and check that the image's alternative text matches “Logo 1.” Also check Wrap Text: an inline picture is not a floating Shape and will not be found by this macro.
Can I use the same approach for an image in the document body?
Yes. For a floating image in the main document body, search ActiveDocument.Shapes for its AlternativeText and apply ZOrder to the matching shape.




