How to Add a Conditional Separator Between Word StyleRef Fields
Question details
The user needs to display a vertical separator between two fields (e.g., Name and Company) in a Word document header, but only when the second field actually contains text.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Setting up a dynamic document header or letterhead that conditionally formats separators based on whether optional user input is present.
- Observed behavior
- The conditional separator fails to display correctly or evaluate the condition, often because the user manually types field braces instead of inserting actual Word fields.
Ensure you have applied your specific styles (such as 'Name' and 'Company') to the correct text in your document. Remember that field code braces {} must be inserted using keyboard shortcuts, not typed manually.
Use Nested IF Fields for Conditional Separators
Construct a conditional statement using Word's IF field to check if the second StyleRef field is empty, displaying the separator only if it contains text.
Word's field codes allow for dynamic document elements. By using an IF field to evaluate a StyleRef field, you prevent stray formatting (like an empty vertical pipe) when optional data is omitted.
Press Ctrl + F9 to insert the first set of field braces {}. Inside the braces, type StyleRef "Name" to pull the text styled as Name.
Press Ctrl + F9 again to create a new set of braces {} immediately after the first field. Type IF " inside these new braces.
While still inside the IF field's quotes, press Ctrl + F9 to insert another set of braces. Type StyleRef "Company" inside this nested field.
Click outside the nested field's closing brace but still inside the IF field. Type " <> "" " | " "" to complete the statement. This tells Word to output " | " if the Company style is not empty.
Outside the IF field, press Ctrl + F9 and type StyleRef "Company" to display the actual company name when it exists.
Press Alt + F9 to toggle from viewing field codes to viewing the result, then press F9 to update all fields based on your document's current text.

Create Conditional Fields Easily in WPS Writer
WPS Office Writer fully supports advanced field codes, including StyleRef and nested IF statements. You can seamlessly insert, toggle, and update dynamic headers just as you would in Microsoft Word.
- 1. Access the Header: Open your document in WPS Writer and double-click the header area to place your cursor where you want the dynamic fields.
- 2. Insert Field Codes: Press Ctrl + F9 to insert field braces, then input your StyleRef and IF logic exactly as you would in Word.
- 3. Use the Interface Alternative: Alternatively, go to the 'Insert' tab and click 'Field' to use a dialog box to select and configure your field types without memorizing syntax.
- 4. Update and Preview: Right-click the inserted fields and select 'Update Field' or press F9 to display the final dynamic result.

Frequently Asked Questions
Why is my IF field showing the code instead of the result?
You likely have field codes toggled on. Press Alt + F9 (or Fn + Alt + F9 on some laptops) to toggle between viewing the field code and viewing the final field result.
Can I use a different separator, like a hyphen or bullet?
Yes. In the field code syntax, simply replace the vertical bar with your preferred character, such as a hyphen (-) or bullet symbol (•), making sure to keep it wrapped in quotation marks.
Why isn't my conditional separator disappearing when the company name is empty?
This usually happens if the paragraph containing the 'Company' style has a blank space, non-breaking space, or an empty paragraph return. The field evaluates these invisible characters as actual text. Ensure the styled text area is completely cleared of any formatting or spaces.




