Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2006

Tip: Looking for answers? Try searching our database.

Strange Problem with PAGEREF and Table of Contents in Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sheqman - 17 Feb 2006 17:17 GMT
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
Peter Jamieson - 19 Feb 2006 18:30 GMT
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

>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
[quoted text clipped - 19 lines]
>
> Rasheq
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.