Document Editing Problems

Use STYLEREF, PAGEREF, and IF Fields in Word Headers

Elise WilliamsElise Williams Nov 22, 2026 868 views

Question details

Create Word headers that display a Heading 2 when appropriate and fall back to Heading 1, with separate odd and even headers if needed.

Use STYLEREF, PAGEREF, and IF Fields in Word Headers
Product
Microsoft Word
Device & OS
not provided
Scenario
A document uses heading styles and needs conditional header text, potentially with page-reference logic.
Observed behavior
STYLEREF has no direct page-reference switch, and Word has no documented TRIM calculation field. Hidden heading markers can support the heading logic but may not produce the desired page-number behavior.
Before you start

Apply Heading 1 and Heading 2 styles consistently, and decide which pages should use each header. In Word, use Home > ¶ to show formatting marks and hidden text while placing markers.

Solution 1Recommended

Use hidden Heading 2 markers and an IF field

Use this workaround to select Heading 2 or fall back to Heading 1 without a TRIM field or a STYLEREF page-reference switch.

STYLEREF searches the current page for the specified style and can fall back to an earlier occurrence. Hidden Heading 2 paragraphs provide a recognizable marker for the IF test, but their placement affects the result.

1
Add a marker

On the first page, add a paragraph containing NO_SUBHEADING and apply Home > Styles > Heading 2. Select the marker text and paragraph mark, then open the Font dialog and select Hidden.

2
Add markers after headings

Add another hidden NO_SUBHEADING paragraph in Heading 2 style after each actual Heading 2. Check its position against page breaks so that STYLEREF finds the intended heading or marker.

3
Open the header

Double-click the header area. If you need separate designs, enable Different Odd & Even Pages on the Header & Footer tab and edit each header separately.

4
Insert the conditional field

Insert this field structure in the header: { IF "{ STYLEREF "Heading 2" }" = "NO_SUBHEADING" "{ STYLEREF "Heading 1" }" "{ STYLEREF "Heading 2" }" }. Use Ctrl+F9 for each pair of field braces rather than typing the braces, and enter the remaining text inside them.

5
Update and check pages

Select the header field and press F9, then use File > Print to preview pages with and without Heading 2. Adjust marker placement where the displayed heading is not the one you want.

Use hidden Heading 2 markers and an IF field
Check marker placement: A marker that appears before an actual Heading 2 on the same page can be selected instead of that heading. Hidden markers can also affect document structure, and this workaround does not guarantee the desired page-number behavior.
Free Microsoft Office alternative

Edit Word documents with WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Move existing files into WPS Writer easily, but verify complex conditional fields and headers before relying on them.

Edit document headers and apply heading styles in WPS WriterCompatible with Microsoft Word DOC and DOCX formatsFamiliar editing interface for an easier transition from OfficeFree and lightweight for everyday document editing
microsoft office alternative - wps office

Frequently Asked Questions

Can STYLEREF return the page number of the heading it finds?

STYLEREF has no direct page-reference switch. PAGEREF can return the page of a named bookmark, but it does not automatically refer to the heading selected by STYLEREF.

How do I insert nested Word field braces?

In the header, press Ctrl+F9 for each pair of field braces. Type the field instructions inside the braces, then select the completed field and press F9 to update it.

Why does my header show the hidden marker instead of a heading?

STYLEREF may find the marker first on the page. Show formatting marks with Home > ¶, inspect the marker and heading positions, and adjust the placement before updating the header field.

How do I make odd and even headers different?

Double-click a header and enable Different Odd & Even Pages on the Header & Footer tab. Edit the odd-page and even-page headers separately.

Is there a TRIM calculation field in Word?

Word does not provide a documented TRIM calculation field. For this header scenario, use an exact marker comparison in an IF field instead of relying on TRIM.