I finally understood why these methods do not work:
shape.ZOrder(MsoZOrderCmd.msoBringInFrontOfText); shape.ZOrder(MsoZOrderCmd.msoBringToFront);
The problem was that I added a Shape object to the HeaderFooter section, but the shape displayed on top of it was defined in the Document . Z-ordering only applies to other forms within the same section where your object is located (regardless of whether your object is in the actual document, header, footer, etc.).
So instead of this code, add the form to a specific section:
var shape = section.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, "Example text...", "Calibri", 72, MsoTriState.msoFalse, MsoTriState.msoFalse, 0, 0, section.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range) as Shape; shape.ZOrder(MsoZOrderCmd.msoBringInFrontOfText); shape.ZOrder(MsoZOrderCmd.msoBringToFront);
I used this code to add it to my document directly, and then apply the Z-order to it, and it really worked. It appeared above all the other objects that were part of my template:
var shape = document.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, "Example text...", "Calibri", 72, MsoTriState.msoFalse, MsoTriState.msoFalse, 0, 0) as Shape; shape.ZOrder(MsoZOrderCmd.msoBringToFront);
Writing macros in Word, the second edition states this very clearly:
The ZOrder method sets the z-order of the Shape object relative to another object. Note that the method does not establish an absolute z-order.
Thus, the absolute Z-order depends on other factors, for example, where the Shape is in this case.