Table of contents can't be merged

H

Håkan Ehrsson

Hi,
I have a VB6 program that performes a MailMerge.
But if my template contains a Table of contents, it will
loose all references when merged.
I read something about problem with FormFields in the
knowledgebase article Q211308, but I can't make it work.

The solution was to loop through all FormFields and store
them temporary, and restore them after the MailMerge.

But in my case the document doesn't contain any text
FormFields, just TOC fields.

Please, does anybody have a clue?
 
P

Peter Jamieson

There are two basic problems with merging a TOC:
a. the TOC field is lost - at best, you will see a copy of the /result/ of
the TOC field, possibly including Hyperlinks (each "copy" of the TOC will
convert to exactly the same text and destination bookmarks)
b. all bookmarks are in any case lost, so any hyperlinks wil point to
non-existent destinations.

However, since paragraph styles and TC fields are both preserved, you could
re-insert the necessary TOC field(s) after the merge (perhaps use some
placeholder text or a field that survies the merge to tell you where to put
the TOC), then refresh the document fields. This is obviously easier if you
know what type of TOC field should be in there - if you are trying to write
a generic mailmerger so that anyone's TOC survives the process, you would
probably have to use VB to
a. get the existing TOC field code
b. replace the TOC by placeholder text or whatever
c. proceed as above. You would probably also need to know whether th user
wanted one TOC, or one TOC per section , in the final output.
 
H

Håkan Ehrsson

It's something like that I tried, but I can't seem to
copy the content back into the field, I get a "type
mismatch" error when assigning a string to Field.Code.
What kind of data should it be?
 
P

Peter Jamieson

It's a range.

oField.Code.Text = "TOC etc." should do it, or specify the text when you
invoke oDoc.Fields.Add

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/

It's something like that I tried, but I can't seem to
copy the content back into the field, I get a "type
mismatch" error when assigning a string to Field.Code.
What kind of data should it be?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top