#1
|
|||
|
|||
How to hyperlink an index entry to a bookmark in a document?
I see the following error message in index on linking an index entry to a bookmark.
Error! Reference source not found.Error! Reference source not found.Error! Reference source not found.Error! Reference source not found.Error! Reference source not found.Error! Reference source not found.Error! Reference source not found.Brief History of Vedas, 1 ("Brief History of Vedas, 1" is the index entry (manual entry); a paragraph in the body of text is assigned a Bookmark.) I use windows 10 and Office365. I request a way to avoid the error message? Last edited by Ashok P; 02-27-2021 at 10:25 PM. Reason: for clarity |
#2
|
||||
|
||||
Word does not support the hyperlinking of index entries.
As for your index entry error messages, that suggests the related XE fields have been poorly coded.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
The following code converts a Word Index to a hyperlinked form, where each hyperlink points to the first corresponding index entry on each indexed page. 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() ' Sourced from: https://www.msofficeforums.com/word-vba/46554-how-hyperlink-index-entry-bookmark-document.html 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 • 2 or 3 references on the same page, where just the single page entry is mentioned in the index; or • 10 entries spanning multiple pages and represented as, say, 6-11, where there's only one entry on page 6 & two on page 11, plus multiple entries on the other pages. Hyperlinks simply cannot point to multiple destinations; they simply don't and can't work that way - in any environment, not just in MS Word. That is why the above code links to only the first entry on each of the pages explicitly referenced in the index. Moreover, the code only links back to the XE fields, not to the content to which they refer.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
word 2002 hyperlink to a bookmark in the same document | anon125 | Word | 4 | 11-24-2020 02:16 PM |
How to add a hyperlink in VBA to a bookmark within a document | jroger05 | Word | 4 | 07-20-2016 06:37 AM |
Get Paragraph index from bookmark starting index | vince692 | Word VBA | 6 | 05-13-2016 04:51 AM |
Macro for mark index entry for every word in a document? | Jay Jay | Word VBA | 5 | 08-13-2015 03:44 PM |
Skipping an Index entry | philippe.delobbe | Mail Merge | 0 | 04-30-2015 05:49 AM |