Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2017, 08:03 AM
boywonder boywonder is offline use hyperlink in page number in index Windows 7 64bit use hyperlink in page number in index Office 2013
Novice
use hyperlink in page number in index
 
Join Date: Jul 2017
Posts: 1
boywonder is on a distinguished road
Question use hyperlink in page number in index


I use the hyperlinks to the TOC in MS Word, but is there a way to set the page number in the Index area to a hyperlink?
Reply With Quote
  #2  
Old 07-27-2017, 09:32 AM
Charles Kenyon Charles Kenyon is offline use hyperlink in page number in index Windows 10 use hyperlink in page number in index Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

There is no way, built into Word, to do this.
Reply With Quote
  #3  
Old 07-27-2017, 03:18 PM
macropod's Avatar
macropod macropod is offline use hyperlink in page number in index Windows 7 64bit use hyperlink in page number in index Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Indexes in Word can't do this, for the simple reason that a given index entry could potentially reference multiple fields on the same page; a hyperlink can only go to one such entry and, given that your document's pagination might change if you change the active printer driver, margins, etc., there is no way for Word to know beforehand which item to link to.

The following macro converts a Word Index to a hyperlinked form, where each hyperlink points to the first corresponding index entry on each indexed page. One consequence of this is that the Index will no longer update, so its use would ideally be restricted to documents whose editing has been completed and are not to be viewed on systems using different printer drivers than the one on which the macro is run.

Code:
Sub IndexHyperlinker()
Application.ScreenUpdating = False
Dim Fld As Field, Rng As Range, StrIdx As String, StrList As String, i As Long, j As Long
StrList = vbCr
With ActiveDocument
  .Fields.Update
  For Each Fld In .Fields
    With Fld
      If .Type = wdFieldIndexEntry Then
        StrIdx = Trim(Replace(Replace(Split(.Code.Text, "XE ")(1), ", ", "_"), Chr(34), ""))
        If InStr(StrList, vbCr & StrIdx & ",") = 0 Then
          i = 0
          StrList = StrList & StrIdx & "," & i & vbCr
        Else
          i = Split(Split(StrList, vbCr & StrIdx & ",")(1), vbCr)(0)
        End If
          StrList = Replace(StrList, StrIdx & "," & i & vbCr, StrIdx & "," & i + 1 & vbCr)
          i = i + 1
        Set Rng = .Code
        With Rng
          .Start = .Start - 1
          .End = .End + 1
          .Bookmarks.Add Name:=StrIdx & i, Range:=.Duplicate
        End With
      End If
    End With
  Next
  Set Rng = .Indexes(1).Range
  With Rng
    .Fields(1).Unlink
    If Asc(.Characters.First) = 12 Then .Start = .Start + 1
    For i = 1 To .Paragraphs.Count
      With .Paragraphs(i).Range
        StrIdx = Replace(Split(.Text, vbTab)(0), ", ", "_")
        .MoveStartUntil vbTab, wdForward
        .Start = .Start + 1
        .End = .End - 1
        For j = 1 To .Words.Count
          If IsNumeric(Trim(.Words(j).Text)) Then
            .Hyperlinks.Add Anchor:=.Words(j), SubAddress:=GetBkMk(Trim(.Words(j).Text), StrIdx), TextToDisplay:=.Words(j).Text
          End If
        Next
      End With
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub

Function GetBkMk(j As Long, StrIdx As String) As String
Dim i As Long
With ActiveDocument
  For i = 1 To .Bookmarks.Count
    If InStr(.Bookmarks(i).Name, StrIdx) = 1 Then
      If .Bookmarks(i).Range.Information(wdActiveEndAdjustedPageNumber) = j Then
        GetBkMk = .Bookmarks(i).Name: Exit For
      End If
    End If
  Next
End With
End Function
For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
index, page index, toc



Similar Threads
Thread Thread Starter Forum Replies Last Post
use hyperlink in page number in index Add external hyperlink to a calculated number Harleygal17 Excel 4 04-06-2017 11:38 PM
use hyperlink in page number in index Start page number on page 3, go to page not working properly MetroBOS Word 7 01-30-2016 11:31 PM
use hyperlink in page number in index Index Hyperlink Workaround Phil H Word VBA 9 10-30-2014 05:14 AM
Page number with chapter number but not from Heading 1 alpruett Word 5 06-04-2014 02:00 PM
use hyperlink in page number in index Index page number formatting kenelder Word 1 09-06-2013 03:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:19 AM.


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