Hi =?Utf-8?B?ZnZ0YQ==?=,
if you want to go this route, then I recommend Peter Jamieson's approach, instead, that
basically flips through each record, sending that to the printer. Then you don't have to
recreate the bookmarks at all. (See below my sig)
However, I don't think this would help with the TOC problem, if you want a TOC for each
merge record? Mail merge also unlinks most field codes (turns them to plain text), so
you'd have the additional problem of recreating the TOC.
What, more exactly, are you trying to accomplish with the mail merge? You might be better
off to simply do the whole thing using VBA...
Doug Robbings posted this in an effort to help a member in regards to retaining
bookmarks in a merged document. I was wondering if this macro could be applied to solve
my problem also:
"If you run the following macro when the mailmerge main document is active,
it will execute the merge to a new document, split that new document into
individual documents with each document corresponding to a record in the
datasource and then it will recreate the bookmarks that were in the main
document in each of those documents and save and close them with a filename
"Letter#" where # is a sequential number:"
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply in the
newsgroup and not by e-mail
Sub ProduceOneDocPerSourceRec()
'
' NB, needs bettor error management and doubtless other things a VBA expert ' will point
out.
Dim intSourceRecord
Dim objMerge As Word.MailMerge
Dim strOutputDocumentName As String
Dim TerminateMerge As Boolean
' Need to set up this object as the ActiveDocument changes when the ' merge is performed.
Besides, it's clearer.
Set objMerge = ActiveDocument.MailMerge
With objMerge
' If no data source has been defined, do it here using OpenDataSource.
' But if it is already defined in the document, you should not need to define it here.
' .OpenDataSource _
' Name:="whatever"
intSourceRecord = 1
TerminateMerge = False
Do Until TerminateMerge
.DataSource.ActiveRecord = intSourceRecord
' if we have gone past the end (and possibly, if there are no records)
' then the Activerecord will not be what we have just tried to set it to
If .DataSource.ActiveRecord <> intSourceRecord Then
TerminateMerge = True
' the record exists
Else
' while we are looking at the correct activerecord,
' create the document path name
' e.g.
strOutputDocumentName = _
"c:\Training\course details_" & _
.DataSource.Datafields("Employee_no").Value & _
".doc"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute
' The Activedocument is always the output document
' Add any parameters you need to these calls
ActiveDocument.SaveAs strOutputDocumentName
ActiveDocument.Close
intSourceRecord = intSourceRecord + 1
End If
Loop
End With
End Sub