The table of contents is no longer shaded or is not "hot", meaning it won't jump to the place in document if click a particular title. It just takes you to the beginning of the document.
Yes it is highlighted like a www hyperlink. When I used Word 2000, I was not having this problem.
Cindy,
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:
' Throwaway Macro created by Doug Robbins to "preserve" bookmarks during a
mailmerge
'
Dim abm As Bookmark, bmrange As Range, i As Long, Result As Document, j As
Long, k As Long
Dim Target As Document, Letter As Range, source As Document
Set source = ActiveDocument
i = 1
For Each abm In ActiveDocument.Range.Bookmarks
System.PrivateProfileString("c:\bookmarks.txt", "bookmarkNames",
"bookmark" & i) = abm.Name
abm.Range.InsertBefore "#"
abm.Range.InsertAfter "#"
i = i + 1
Next
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Set Result = ActiveDocument
For j = 1 To Result.Sections.Count - 1
Set Letter = Result.Sections(j).Range
Letter.End = Letter.End - 1
Set Target = Documents.Add
Target.Range = Letter
k = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="#*#", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set bmrange = Selection.Range
bmrange.Characters(bmrange.Characters.Count).Delete
bmrange.Characters(1).Delete
Target.Bookmarks.Add
System.PrivateProfileString("c:\bookmarks.txt", "bookmarkNames", "bookmark"
& k), bmrange
k = k + 1
Loop
End With
Target.SaveAs FileName:="Letter" & j
Target.Close
Next j
source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="#*#", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set bmrange = Selection.Range
bmrange.Characters(bmrange.Characters.Count).Delete
bmrange.Characters(1).Delete
Loop
End With
> The table of contents is no longer shaded or is not "hot", meaning it won't jump to the place in document if click a particular title. It just takes you to the beginning of the document.
>
[quoted text clipped - 33 lines]
> > This reply is posted in the Newsgroup; please post any follow question or reply in the
> > newsgroup and not by e-mail :-)
Cindy M -WordMVP- - 18 Jun 2004 17:47 GMT
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,
[quoted text clipped - 3 lines]
> 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