Indexing a table of contents RRS feed

  • Question

  • Dear Technician:

    I hope you are doing well today.  I thank you for your time.  My question is about how to create an indexed table of contents that will translate to the Kindle format for my ebook.  I have a table of contents written at the begginning of the ebook, but Kindle does not recognize it.  The reader may only access the TOC from the TOC page using hyperlinks to each chapter of the book.  I would like to create the index that allows the kindle device to select chapters.  Again I thank you for your time.  Leo.

    Tuesday, August 12, 2014 5:00 PM


  • If the problem is that the Word Table Of Contents is being converted to plain text when using the Kindle format, you may need to convert it to a set of hyperlinks instead.

    The following macro converts a Table of Contents to Hyperlinks (without page #s). Since hyperlinks don't update the way TOC fields do, it's probably best to not do the conversion until the document is otherwise finalised.

    Sub ConvertTOC2Hyperlinks()
    Dim RngTOC As Range, RngItem As Range, StrBkMkList As String, StrTmp As String, i As Long
    With ActiveDocument
      With .TablesOfContents(1)
        For i = 2 To .Range.Fields.Count
          StrBkMkList = StrBkMkList & "|" & Split(Trim(.Range.Fields(i).Code.Text), " ")(1)
        Set RngTOC = .Range
      End With
      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, _
    End With
    End Sub

    Paul Edstein
    [MS MVP - Word]

    Tuesday, August 12, 2014 10:25 PM