Hi, Suvi. I'm glad you used my file, because now we can be specific. Your code here loops through just the Bookmarks in my file, replacing their content. That is not what I am asking help for. Let me try to explain better:
The very first Bookmark (named "NameSchoolDist") is on Page 1 of my file, found immediately below the line "On behalf of:". Now, there are 2
REF Fields on Page 2 that I would like to figure out how to have them update to display the exact same content of the "NameSchoolDist" Bookmark. As you can see in your result.doc file,
these 2 fields still read "NameSchoolDist" when I would expect them to read "Contentof the bookmark[0]" after being updated (but updated how???). These fields have a FieldType of "FieldRef" which means they reference something else in the document, which in my document, they happen to reference a Bookmark. In fact, if you right-click on either of these Fields, you will get a pop-up menu (at least I do while using Word 2007) and you can "Update Field" or "Edit Field..." or "Toggle Field Codes". So, if you choose to "Update Field" the content WILL update to read "Contentof the bookmark[0]", but I want my code to do this automatically, as a last step before saving the document.
I know that if a user does a Print Preview of this document, all referenced fields DO get updated nicely, but there has to be a way to update all referenced fields automatically (via code).
Again, my question is: How do I update fields that reference bookmarks? Using the Word API, this was done simply by "selecting" the entire document, and then calling an Update() method, as such:
- Code: Select all
objWord.Selection.WholeStory(); // Select the entire document.
objDoc.Fields.Update(); // Update all Word Fields that are linked to the Word Bookmarks.
objWord.Selection.Collapse(); // De-select entire document; returning to beginning.
Also, here's an example of how to do it using VBA macro within Word:
- Code: Select all
Dim aStory As Range
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
Again, I see by reading the Spire.Doc API documentation that there's a property called "IsUpdateFields" on "document". What does that do? If I set to true, what do I do next to actually update the fields?
Thank you!