Document Editing Problems

How to Add a Conditional Separator Between Word StyleRef Fields

Maira MehtabMaira Mehtab Sep 28, 2026 875 views

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.

How to Add a Conditional Separator Between Word StyleRef Fields
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.
Before you start

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.

Solution 1Recommended

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.

1
Insert the first StyleRef field

Press Ctrl + F9 to insert the first set of field braces {}. Inside the braces, type StyleRef "Name" to pull the text styled as Name.

2
Start the conditional IF field

Press Ctrl + F9 again to create a new set of braces {} immediately after the first field. Type IF " inside these new braces.

3
Insert the nested StyleRef field

While still inside the IF field's quotes, press Ctrl + F9 to insert another set of braces. Type StyleRef "Company" inside this nested field.

4
Complete the IF field logic

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.

5
Add the final StyleRef field

Outside the IF field, press Ctrl + F9 and type StyleRef "Company" to display the actual company name when it exists.

6
Update the fields

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.

Use Nested IF Fields for Conditional Separators
Crucial Step: Never type the curly braces {} manually with your keyboard. You must use Ctrl + F9 (or Cmd + F9 on Mac) to insert functional Word field braces.
Dynamic Fields in WPS Writer

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. 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. 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. 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. 4. Update and Preview: Right-click the inserted fields and select 'Update Field' or press F9 to display the final dynamic result.
100% compatible with Microsoft Word field codes (.docx)Free to download and use for daily document editingLightweight with a familiar, easy-to-use interface
microsoft office alternative - wps office

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.