MS Word - Bookmarks in Headers not updating correctly

RichCowell

Board Regular
Joined
Dec 5, 2013
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I've got a document I'm using as a template with several sections.

Page 1 is a title page with the:
  1. Document Title
  2. Published Date
  3. Updated Date
Those three items are all bookmarks.

Those three items are also included in the header of each page.

When I'm ready to finalise the file and update everything with F9, only the first page of each section updates - although the other pages show as having updated, when I exit the Header & Footer, the subsequent pages in each section revert back to the original text, and only the first page in each section has updated.

I've seen elsewhere online that it may be resolved with the following code:
VBA Code:
foreach (Aspose.Words.Bookmark bookMark in
doc.Range.Bookmarks)
{
bookMark.Text = “New Text”;

}
Which I've added but it doesn't seem to make any difference.

Is anyone able to point me in the right direction?

(Also - if anyone knows of a way of updating the headers in all sections with one command rather than having to do each section individually, I'd be eternally grateful too!)

Thanks,

Rick
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Quick update - I've just edited the cross-references to remove the hyperlinks and it looks like they're updating correctly now.
If anyone knows of a way of updating headers in all sections still I'd be really grateful to learn how.
 
Upvote 0
So what is in the headers, the hard-coded text, cross-references, StyleRefs fields, something else?
 
Upvote 0
Screenshots of the header and code view of the header below:

2022-12-07_122539.png


2022-12-07_122553.png


It's the Title, Published and Updated REFs that aren't updating - I thought they were yesterday now they are in Section 2, but not in the subsequent sections.

I can't work it out - it's not the end of the world if I have to do it manually, but it should work...
 
Upvote 0
Thanks - I took the code back out as it didn't do anything, then I realised (after posting) that it may be linked with a 3rd party addin...
I'll check out that site in the office tomorrow...
Thanks again,
Rick
 
Upvote 0
@Macropod - thanks for your help - I'm going to leave it for now and just do it manually. That code was for Aspose.Words - which I don't have, and I've not got time to work how if/how that can sort it.
It's a shame find/replace doesn't work in headers and footers too - that would have been a nice workaround.
 
Upvote 0
It's a shame find/replace doesn't work in headers and footers too - that would have been a nice workaround.
It does work there - provided the code is written to do so.

A simple workaround would be to.
1 Apply unique Style names to each of your Document Title, Published Date, & Updated Date ranges in the document body, (e.g. Title, Published , & Updated)
2. Replace the 'REF' in the cross-reference fields with 'STYLEREF' and delete \* MERGEFORMAT from the fields.
With those changes, the fields in the header will update any time the text in the Title, Published , & Updated Style ranges is updated.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top