Fix Word IF and STYLEREF Field Errors in Headers
Question details
The user encounters an unknown switch argument error when trying to use IF and STYLEREF fields to compare heading text in a document header.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating dynamic headers that compare heading text at the top and bottom of a page to display conditional information.
- Observed behavior
- An unknown switch argument error or unresolvable field code appears, typically caused by manually typing curly braces, incorrect syntax, or missing spaces.
Ensure that your document actually contains text formatted with the specific heading style (e.g., Heading 2) that you are trying to reference in your header.
Use Field Shortcuts and Correct Syntax
Insert field codes using keyboard shortcuts instead of manual typing, and ensure strict adherence to spacing and switch arguments.
Word processors require special embedded codes for fields. Typing standard curly brackets on your keyboard will result in regular text, not a functional field code. You must use the correct shortcut to generate field braces.
Press Ctrl+F9 to insert the special curly brackets { } required for field codes. Do not type them manually using your keyboard.
Type the field structure exactly as follows: {IF {STYLEREF "Heading 2"}={STYLEREF "Heading 2" \l} "T" "F"}. Remember to use Ctrl+F9 for the inner STYLEREF brackets as well.
Ensure there are spaces between the IF statement, the first STYLEREF field, the equals sign, the second STYLEREF field, and the True/False text outputs.
Right-click the field code and select 'Update Field', or simply press F9 to apply the changes and display the conditional result.

Verify Document Styles are Applied
Ensure the referenced style exists and is applied to text in the document to prevent STYLEREF errors.
Effortlessly Insert and Manage Document Fields in WPS Office
WPS Writer offers an intuitive interface for inserting advanced document fields like IF and STYLEREF without needing to memorize complex syntax or keyboard shortcuts.
- 1. Open your document: Launch WPS Writer and open the document where you need to add dynamic headers.
- 2. Access the Header: Double-click the top margin of the page to open the Header & Footer edit mode.
- 3. Insert Field: Go to the Insert tab, click on 'Quick Parts', and select 'Field' to choose IF and STYLEREF from a user-friendly list.

Frequently Asked Questions
Why can't I just type the curly brackets for field codes?
Word processors treat manually typed curly brackets { } as regular text. To create a functioning field code, you must insert special field brackets by pressing Ctrl+F9.
What does the \l switch do in a STYLEREF field?
The \l switch instructs the software to search for the specified style starting from the bottom of the current page and working upwards, rather than from the top down.
Why does my STYLEREF field say 'Error! No text of specified style in document'?
This error occurs when the document does not contain any text formatted with the exact style name referenced in your field code. Ensure you have applied the referenced style (e.g., Heading 2) to at least one paragraph.
Can I use other styles besides Heading 2 in my STYLEREF field?
Yes, you can reference any built-in or custom style by replacing "Heading 2" in the field code with the exact name of your desired style, keeping the quotation marks intact.




