A Table of Contents in Word automatically hyperlinks to the corresponding headings - provided you've set things up correctly. The simplest way to do the setup is to use Word's heading Styles; the Table of Contents (TOC) field automatically picks those up.
Accordingly, I don't follow what you mean by:
Quote:
Originally Posted by Redgum
I highlighted the relevant chapter, clicked Add Bookmark, and then went to the chapter reference in the contents section and highlighted it, then clicked add Hyperlink. No problem - worked perfectly.
|
If you're using a Word Table of Contents, anything you add to it will be lost as soon as it updates (e.g. by previewing/printing the document)
Since a Word Table of Contents won't work in the ebook format, what you could do is to use a Word Table of Contents for editing purposes and, when you're done convert it to hyperlinks, which is what the following macro does:
Code:
Sub ConvertTOC2Hyperlinks()
Dim RngTOC As Range, RngItem As Range, StrBkMkList As String, StrTmp As String, i As Long
With ActiveDocument
With .TablesOfContents(1)
.Update
If InStr(.Range.Fields(1).Code.Text, "\n") = 0 Then
For i = 3 To .Range.Fields.Count Step 2
StrBkMkList = StrBkMkList & "|" & Split(Trim(.Range.Fields(i).Code.Text), " ")(1)
Next
Else
For i = 2 To .Range.Fields.Count
StrBkMkList = StrBkMkList & "|" & Replace(Split(Trim(.Range.Fields(i).Code.Text), " ")(2), """", "")
Next
End If
Set RngTOC = .Range
End With
RngTOC.Fields.Unlink
For i = 1 To UBound(Split(StrBkMkList, "|"))
Set RngItem = RngTOC.Paragraphs(i).Range
RngItem.End = RngItem.End - 1
StrTmp = Replace(Split(StrBkMkList, "|")(i), "Toc", "HL")
.Bookmarks.Add Name:=StrTmp, Range:=.Bookmarks(Split(StrBkMkList, "|")(i)).Range
.Bookmarks(Split(StrBkMkList, "|")(i)).Delete
.Hyperlinks.Add Anchor:=RngItem, SubAddress:=.Bookmarks(StrTmp).Range, _
TextToDisplay:=.Bookmarks(StrTmp).Range.Text
Next
End With
End Sub
For PC macro installation & usage instructions, see:
http://www.gmayor.com/installing_macro.htm.