Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-19-2015, 08:43 PM
macropod's Avatar
macropod macropod is offline Formatting for internal hyperlinks question. Windows 7 64bit Formatting for internal hyperlinks question. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,513
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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 View Post
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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Number Formatting Question Redgum Word 3 09-17-2015 04:08 PM
Formatting for internal hyperlinks question. Drop down menus colour formatting - Newbie question TerryStevenson Word 2 09-17-2013 10:43 AM
Formatting for internal hyperlinks question. Conditional formatting question based on cell date Cosmo Excel 2 04-08-2013 12:12 PM
Formatting for internal hyperlinks question. Formatting question... rwear Word 1 01-30-2011 11:36 PM
Excel 2007 - Question on conidial formatting? jerrymbna22 Excel 2 03-24-2010 11:48 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft