Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Jalou
    Guest

    TOC Page Number Hyperlinks

    Anyway to prevent those hyperlinks in the TOC (aside from deleting the h switches after the fact)?

    Thanks.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: TOC Page Number Hyperlinks

    Hi,

    Are you talking about a Word 2000 TOC? - I haven't been using Word 2000 for too long and haven't played around with these much yet, but it looks like the issue is that they behave differently from Word 97 TOCs - in a Word 97 TOC, only the page number reference is an active link back to a location in the document proper, while in Word 2000 TOCs each line reference in its entirety is a hyperlink.

    Here's a macro which will delete the hyperlinks in a Word 2000 TOC, turning it into a 'Word 97-style' TOC:

    <pre>Sub RemoveHLinksFromTOC()
    'Gary Frieder January 2001
    'Purpose: Changes a Word 2000 TOC to a "Word 97-type" TOC
    ' i.e. only the TOC page reference is a link
    Dim rngTOCRng As Range
    Dim n As Long
    Set rngTOCRng = ActiveDocument.TablesOfContents(1).Range
    'Remove hyperlinks
    For n = rngTOCRng.Hyperlinks.Count To 1 Step -1
    rngTOCRng.Hyperlinks(n).Delete
    Next n
    'Remove the "remmant" blue underscore:
    With rngTOCRng.Font
    .Underline = wdUnderlineNone
    .Color = wdColorBlack
    End With
    End Sub
    </pre>

    Hope this helps,
    Gary

  3. #3
    Topsy
    Guest

    Re: TOC Page Number Hyperlinks

    Thanks Gary, you are correct, this never happened in Office 97. I will try the macro. I have discovered through trial and error that there are hidden bookmarks in the Hyperlink fields in my TOC. I went to Insert/Bookmarks and clicked on Hidden Bookmarks and they are all there.
    Thanks for the macro.

  4. #4
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: TOC Page Number Hyperlinks

    I suspect that deleting the l switch is easier. I like the hyperlinks for documents that I use and edit online. (In Word 2000 they don't show up with underlines.) If what you are after is a printed document, though, and you are printing in Word 97 it looks bad. Another alternative, if you don't have any other hyperlinks in your document (or even if you do) is to change the hyperlink character style to get rid of the color and underline.

    However, if you are printing in Word 97, you can update the TOC field, in which case the hyperlinks will disappear because Word 97 can't insert them.
    Charles Kyle Kenyon
    Madison, Wisconsin

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: TOC Page Number Hyperlinks

    Here's another method. I first used For Each...Next with each TOC object, but this caused an infinite loop, for some reason. So, I fell back on the less elegant For...Next:

    Sub NukeTOCHyperlinks()
    Dim colTOCs As TablesOfContents, intCount As Integer
    Set colTOCs = ActiveDocument.TablesOfContents
    For intCount = 1 To colTOCs.Count
    colTOCs(intCount).UseHyperlinks = False
    Next
    End Sub

    I guess someone enterprising could add a MsgBox or make it a toggle...

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC Page Number Hyperlinks

    Hi Jefferson:

    Are there advantages or disadvantages using this macro vs. Gary's above?

    Thanks in advance.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: TOC Page Number Hyperlinks

    > Are there advantages or disadvantages using this macro vs. Gary's above?

    I didn't test it to see. I just thought it simpler to operate on a global property (simpler except for the time it took to find it and program it). One possible issue: if the global property is not changed, could a rebuild of the TOC bring the hyperlinks back?

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: TOC Page Number Hyperlinks

    As a rule of thumb, the more direct approach is usually better, since it's simpler, runs more quickly etc.

    Jefferson's version is more direct, in using the UseHyperlinks property. (I probably would have used it too, if I'd dug a little deeper when doing my version - there's lots of good stuff buried in the object model.)

    The main difference that comes out in testing them is reversibility. Apparently setting UseHyperlinks to False permanently removes the hyperlink capability from that TOC. Updating the TOC won't bring them back. So if you want to nuke the hyperlinks and know you never want them back, then that is the way to go.

    The method I used (of deleting hyperlinks) turns out to be reversible; if you update the TOC the hyperlinks come back. This could be desirable or not, depending on your proclivities.

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC Page Number Hyperlinks

    Hi Gary:

    Thanks for the explanation. I prefer the approach that keeps the TOC the same after updating--otherwise I'd have to redo it each time. I'd like to modify it though to include TOFs, like you did with your other macro. However, if they're to be in one macro, I'd need an If...Then...Else approach in case there were no TOFs. Otherwise, I notice that I get an error that "a member of the collection does not exist".

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: TOC Page Number Hyperlinks

    Hi Phil,

    You might want to put in an If test for both TOCs and TOF:

    (adapted from Jefferson's original

    <pre>Sub NukeTOCTOFHyperlinks()
    Dim colTOCS As TablesOfContents
    Dim colTOFS As TablesOfFigures
    Dim intCount As Integer
    Set colTOCS = ActiveDocument.TablesOfContents
    Set colTOFS = ActiveDocument.TablesOfFigures
    For intCount = 1 To colTOCS.Count
    If intCount > 0 Then
    colTOCS(intCount).UseHyperlinks = False
    End If
    Next
    For intCount = 1 To colTOFS.Count
    If intCount > 0 Then
    colTOFS(intCount).UseHyperlinks = False
    End If
    Next
    End Sub
    </pre>

    Gary

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC Page Number Hyperlinks

    Hi Gary:

    Thanks for the modified macro. The TOF part doesn't work, however. When I run the macro, it stops at

    colTOFS(intCount).UseHyperlinks = False

    & says the named argument does not exist. That's strange because it's the just like the TOC line that works. Hmmm.

  12. #12
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC Page Number Hyperlinks

    I'm wondering if it's caused by the fact that a table of figures is a TOC with a c switch. But then why wouldn't the first part of the macro pick up this different type of TOC?

  13. #13
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: TOC Page Number Hyperlinks

    I would be surprised if the TOF part is needed anyway. Both a standard TOC and the specialised TOF are both TOCs. Have a look at their field codes and the only difference between them is the switches and what they are told to build on.

    Step through the first part and see if the TOF is processed as part of the first loop (it should be as it is a TOC). If it isn't then have a look at moving the Set command for the TOF after the first loop. I suspect that the first loop removes the item on which the second ones loop counter relies on.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  14. #14
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TOC Page Number Hyperlinks

    Hi Andrew:

    Thanks for replying. The macro doesn't remove the hyperlink from the TOF. I put the SET line below the first loop (after Next), but that didn't make a difference. It still says the named argument does not exist. Isn't the "true" or "false" the argument? I'm confused.

  15. #15
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: TOC Page Number Hyperlinks

    Hi Phil,

    I don't have access right now to the version I posted some time ago on DWT - which did work for both TOCs and TOFs (I think - or was it TOAs!). That one used Hyperlinks.Delete rather than UseHyperlinks = False.

    Maybe what could be done is to first do the TOCs using the UseHyperlinks = False method, and then do the TOFs using the Hyperlinks.Delete method.

    If you happen to have a copy of that code, post it, and we can try to patch the two parts together. Otherwise I can try to locate it on my work PC tomorrow.

    Gary

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •