Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
sheqman
 
Posts: n/a
Default Strange Problem with PAGEREF and Table of Contents in Word

I have a program that takes data from an Excel spreadsheet and inserts
into a series of word documents using a mailmerge powered by VBA. I
should note that the mailmerge documents are created from templates.
(i.e. the program creates a document from a word template, then applies
the mail merge to that document and outputs the merged document as a
new document which then gets saved.)

Everything works ok except for one legal document that contains a
Word-generated Table of Contents. The original template has the TOC and
updates it when the document opens. However, when a new document is
created based on this template, the TOC in the new document gets
corrupted. Basically, it creates PAGREF field codes for each entry in
the TOC and loses the TOC functionality. This wouldn't be a problem
except that I have another script that takes the merged word docs and
outputs them to PDF. When the script encounters the document in
question, it replaces the PAGEREF codes with "Error! Bookmark not
defined." Obviously this make the resulting document unusable.

Anyway to get around this problem?

Thanks in advance for your help,

Rasheq

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Strange Problem with PAGEREF and Table of Contents in Word

The problem occurs during the merge and is caused by the fact that Merge
destroys the ToC field, leaving the underlying references to the pages that
headings and/or TC fields are on (either PAGEREF or HYPERLINK fields,
depending on the switches in the ToC field) and destroys all bookmarks, so
the "targets" of the PAGEREF or HYPERLINK fields also disappear.

It's difficult to know what you could do about this in a generic automated
merge unless the merge knows that it has to do something special for the one
document with a ToC. Logically speaking, what you probably need to do is
a. detect whether or not there is a ToC
b. If there is, save all the information necessary to recreate the ToC (ToC
switches, location, and perhaps style info. related to the various ToC
paragraph styles)
c. replace the ToC by some kind of placeholder text, or otherwise remember
its position, during the merge
d. After the merge, re-insert the ToC field, restore any other settings
such as paragraph style settings, and re-execute the ToC field

Alternatively, you could do something like get the users to put the ToC
field in an INCLUDETEXTed document, do the merge, and re-execute that field,
but there are various possible gotchas with that approach.

Peter Jamieson

"sheqman" wrote in message
ups.com...
I have a program that takes data from an Excel spreadsheet and inserts
into a series of word documents using a mailmerge powered by VBA. I
should note that the mailmerge documents are created from templates.
(i.e. the program creates a document from a word template, then applies
the mail merge to that document and outputs the merged document as a
new document which then gets saved.)

Everything works ok except for one legal document that contains a
Word-generated Table of Contents. The original template has the TOC and
updates it when the document opens. However, when a new document is
created based on this template, the TOC in the new document gets
corrupted. Basically, it creates PAGREF field codes for each entry in
the TOC and loses the TOC functionality. This wouldn't be a problem
except that I have another script that takes the merged word docs and
outputs them to PDF. When the script encounters the document in
question, it replaces the PAGEREF codes with "Error! Bookmark not
defined." Obviously this make the resulting document unusable.

Anyway to get around this problem?

Thanks in advance for your help,

Rasheq



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table of contents begins renumbering at every section break frangardengirl Tables 4 February 18th 06 06:21 PM


All times are GMT +1. The time now is 09:46 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"