Document Editing Problems

How to Update a Word IF Field in WPS Writer After Filling a Bookmark with VBA

Anum MushtaqAnum Mushtaq Nov 13, 2026 869 views

Question details

The user needs the correct VBA sequence to make a Word IF field recalculate after filling a bookmark with text in WPS Writer.

Product
WPS Office Writer
Device & OS
not provided
Scenario
The user is automating a Word-compatible document in WPS Writer with a bookmark and an IF field, and expects the IF field to reflect the new bookmark text immediately.
Observed behavior
The IF field still shows the previous result after VBA writes the bookmark value, because the field is not refreshed automatically.
Before you start

Open the document in WPS Writer and confirm that the VBA editor opens with Alt+F11. If the file is saved as .docx, save it as a macro-enabled .docm before adding or editing the macro.

Solution 1Recommended

Recreate the Bookmark and Update the Relevant IF Field

Use this when VBA writes text into a bookmark range and the IF field still displays the stale result; recreating the bookmark restores the field reference before refreshing.

Writing text directly into a bookmark range can delete the bookmark in Word-compatible documents. If the bookmark no longer exists, the IF field cannot recalculate against it, so you must recreate the bookmark before updating the field.

1
Open the VBA editor

In WPS Writer, open the document that contains the bookmark and IF field, then press Alt+F11 to open the VBA editor.

2
Recreate the bookmark after writing text

In the macro module, after the line that assigns the text, call ActiveDocument.Bookmarks.Add with the same bookmark name and the current range so the bookmark exists again.

3
Update the IF field

Still in the macro, call ActiveDocument.Fields.Update to refresh document body fields, or loop through ActiveDocument.Fields and update only the IF field types.

4
Run the macro

Run the macro from the VBA editor with F5 or from the Developer tab > Macros, then return to the document and check that the IF field now shows the new bookmark value.

Recreate the Bookmark and Update the Relevant IF Field
Expected result: The IF field recalculates immediately after the bookmark is recreated and the field update runs.
WPS Writer automation

Update Bookmark-Driven IF Fields Directly in WPS Writer

WPS Office Writer opens Word-compatible documents with field codes and supports macro editing, so you can recreate the bookmark and refresh the IF field without leaving your familiar .docx or .docm workflow.

  1. 1. Open the document in WPS Writer: Launch WPS Office Writer and open the .docx or .docm file that contains the IF field and bookmark.
  2. 2. Open the macro editor: Press Alt+F11 to open the VBA editor, and locate the module where the bookmark text is assigned.
  3. 3. Recreate the bookmark and update fields: After the text assignment, add the bookmark again with the same name, then call ActiveDocument.Fields.Update or update only wdFieldIf fields.
  4. 4. Run and save the document: Run the macro with F5, confirm the IF field result, and save the file as a Word-compatible .docx or .docm document.
Recreate bookmarks and update IF fields from the WPS Writer macro editorFull compatibility with .docx and .doc field codes and bookmarksFree and lightweight Office suite for document automationFamiliar ribbon, keyboard shortcuts, and VBA-like macro flow
microsoft office alternative - wps office

Frequently Asked Questions

Why does a Word IF field not update automatically after VBA fills a bookmark?

The bookmark is often removed when text is written into its range. Recreate the bookmark with the same name and then update the field with ActiveDocument.Fields.Update.

Can I update only the IF field instead of all document fields?

Yes. Loop through ActiveDocument.Fields and call Update only when the field type is wdFieldIf.

Do I need to save the file as macro-enabled before adding VBA?

If you are starting from a .docx file, save it as a .docm so the macro is retained.

Does WPS Office support Word IF fields and bookmarks?

WPS Writer opens Word-compatible documents with field codes and bookmarks, and provides a macro editor for document automation.

What is the safest order for the VBA update?

Assign text to the range first, recreate the bookmark with the same name, and only then update the IF field or all fields.