#1
|
|||
|
|||
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? |
#2
|
|||
|
|||
There is no way, built into Word, to do this.
|
#3
|
||||
|
||||
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 Mac macro installation & usage instructions, see: Word:mac - Install a Macro
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
index, page index, toc |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Add external hyperlink to a calculated number | Harleygal17 | Excel | 4 | 04-06-2017 11:38 PM |
Start page number on page 3, go to page not working properly | MetroBOS | Word | 7 | 01-30-2016 11:31 PM |
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 |
Index page number formatting | kenelder | Word | 1 | 09-06-2013 03:14 PM |