• TOC Page Number Hyperlinks

    Author
    Topic
    #1767633

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

    Thanks.

    Viewing 0 reply threads
    Author
    Replies
    • #1775758

      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:

      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
      

      Hope this helps,
      Gary

      • #1779052

        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.

        • #1779053

          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.

          • #1779290

            Sorry, I should have said the h switch instead of the l switch. The h switch is the one in the TOC field rather than the one in the individual entry listings in the TOC.

            {TOC h z t “Heading 2,2,Heading 2a,2”} is a TOC field.
            {HYPERLINK l “_Toc501741425”} is what I get if with field results (the TOC) displayed, I move the insertion point inside the TOC and press Shift-F9 to toggle the field codes. The rest of the TOC is still there and only the first line is changed.

      • #1779111

        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…

        • #1779226

          Hi Jefferson:

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

          Thanks in advance.

          • #1779227

            > 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?

          • #1779229

            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.

            • #1779230

              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”.

            • #1779231

              Hi Phil,

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

              (adapted from Jefferson’s original:)

              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
              

              Gary

            • #1779249

              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.

            • #1779250

              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?

            • #1779276

              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.

            • #1779281

              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.

            • #1779338

              I think it’s a genuine bug – it’s in the object model, and there’s no reason for it to be misbehaving this way.

            • #1779284

              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

            • #1782836

              Hi Gary:

              I know I’m a couple of months behind, but I still haven’t been able to solve this one. I’d like to get a macro that would permanently (i.e. through updates) remove the Word 2000 hyperlink from both the TOC & TOF. Since it’s one macro & therefore, it would have to test if there were in fact any TOCs or TOFs in the document. I tried doing this with your macro, but couldn’t. Any way to do this?

              This is the macro that you had:

              Sub RemoveHLinksFromTOC_TOF
              Dim rngTOCRng As Range
              Dim rngTOFRng As Range
              Dim n As Long
              Dim c As Long

              Set rngTOCRng = ActiveDocument.TablesOfContents(1).Range
              Set rngTOFRng = ActiveDocument.TablesOfFigures(1).Range

              ‘Remove hyperlinks from TOC:
              For n = rngTOCRng.Hyperlinks.Count To 1 Step -1
              rngTOCRng.Hyperlinks(n).Delete
              Next n
              ‘Remove the “remnant” blue underscore:
              With rngTOCRng.Font
              .Underline = wdUnderlineNone
              .Color = wdColorBlack
              End With

              ‘Remove hyperlinks from TOF:
              For c = rngTOFRng.Hyperlinks.Count To 1 Step -1
              rngTOFRng.Hyperlinks©.Delete
              Next c
              ‘Remove the “remnant” blue underscore:
              With rngTOFRng.Font
              .Underline = wdUnderlineNone
              .Color = wdColorBlack
              End With

              Thanks again.

            • #1782838
            • #1787247

              Hi Gary:

              I just thought I’d let you know that Pieter Janssens developed a macro that removes hyperlinks from both TOC & TOF. If one or the other doesn’t exist, there are no error messages.

              RemoveHyperLinksFromTOC_TOF
              Dim TOC As TableOfContents
              Dim TOF As TableOfFigures
              With ActiveDocument
              For Each TOC In .TablesOfContents
              With TOC.Range
              Do Until .Hyperlinks.Count = 0
              .Hyperlinks(1).Delete
              Loop
              With .Font
              .Underline = wdUnderlineNone
              .Color = wdColorBlack
              End With
              End With
              Next
              For Each TOF In .TablesOfFigures
              With TOF.Range
              Do Until .Hyperlinks.Count = 0
              .Hyperlinks(1).Delete
              Loop
              With .Font
              .Underline = wdUnderlineNone
              .Color = wdColorBlack
              End With
              End With
              Next
              End With

            • #1787251

              Thanks Phil thumbup
              Sorry I let the ball drop on Grace’s request.

              Gary

    Viewing 0 reply threads
    Reply To: TOC Page Number Hyperlinks

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: