How to ensure that endnotes in Word-doc. also are clickable in doc. saved in PDF-format?

Joined
Nov 16, 2016
Messages
2
Reaction score
0
Hi,
How can "clickable" endnotes in Word-document (Office 2010 Home) also be clickable endnotes in PDF-document after one has saved a Word-doc. as a PDF-doc.?

Clickable means here that when the cursor is placed on the left side of an endnote number, one can by a double-click jump to the end of the doc. where the endnote text is. In the same way, one can jump from the end of the doc. and back to the endnote number in the main text. In Word 2010, these endnotes are clickable automatically.

I would be very grateful for help on this task. I do not wish to make - manually - "hyperlinks" for all my over 600 endnotes in my doc.

Thank you in advance.

Best regards,
Soeren
Soeren Lindholt
Denmark
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
578
Reaction score
50
When a document is saved in PDF format, endnote & footnote references cease to act as hyperlinks. The following macro replicates the endnote & footnote references (which become hidden text) with bookmarked hyperlinks. The second macro (KillEndNoteFootNoteHyperLinks) reverses the process.

Furthermore, Word's Note References always point to the reference in the body of the document, not to the endnote or footnote itself. The HyperlinkEndNotesFootNotes macro doesn't change that behaviour. To have the Note References hyperlink to the actual endnote or footnote you could use the third macro (HLnkNoteRefs). The fourth macro (KillHLnkNoteRefs) reverses that process.

Sub HyperlinkEndNotesFootNotes()
Dim SBar As Boolean ' Status Bar flag
Dim TrkStatus As Boolean ' Track Changes flag
Dim Rng1 As Range, Rng2 As Range, StrRef As String, i As Long
' Store current Status Bar status, then switch on
SBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
' Store current Track Changes status, then switch off
With ActiveDocument
TrkStatus = .TrackRevisions
.TrackRevisions = False
End With
' Turn Off Screen Updating
Application.ScreenUpdating = False
With ActiveDocument
'Process all endnotes
For i = 1 To .Endnotes.Count
'Update the statusbar
StatusBar = "Processing Endnote " & i
'Define two ranges: one to the endnote reference the other to the endnote content
Set Rng1 = .Endnotes(i).Reference
Set Rng2 = .Endnotes(i).Range.Paragraphs.First.Range
With Rng1
'Format the endnote reference as hidden text
.Font.Hidden = True
'Insert a number before the endnote reference and bookmark it
.Collapse wdCollapseStart
'To get the actual reference text, we need to cross-reference it!
.InsertCrossReference wdRefTypeEndnote, wdEndnoteNumber, i, False, False
.End = .End + 1
StrRef = .Fields(1).Result
.Fields(1).Delete
.Text = StrRef
.Style = wdStyleEndnoteReference
.Bookmarks.Add Name:="_ERef" & i, Range:=Rng1
End With
'Insert a number before the endnote content and bookmark it
With Rng2
'Format the endnote reference as hidden text
With .Words.First
If .Characters.Last Like "[ " & vbTab & "]" Then .End = .End - 1
.Font.Hidden = True
End With
'Insert a number before the endnote reference and bookmark it
.Collapse wdCollapseStart
.Text = StrRef
.Style = " Endnote Reference"
.Bookmarks.Add Name:="_ENum" & i, Range:=Rng2
End With
'Insert hyperlinks between the endnote references
.Hyperlinks.Add Anchor:=Rng1, SubAddress:="_ENum" & i
.Hyperlinks.Add Anchor:=Rng2, SubAddress:="_ERef" & i
'Restore the Rng1 endnote reference bookmark
.Bookmarks.Add Name:="_ERef" & i, Range:=Rng1
Next
'Give Word a chance to do its housekeeping
DoEvents
'Process all footnotes
For i = 1 To .Footnotes.Count
'Update the statusbar
StatusBar = "Processing Footnote " & i
'Define two ranges: one to the footnote reference the other to the footnote content
Set Rng1 = .Footnotes(i).Reference
Set Rng2 = .Footnotes(i).Range.Paragraphs.First.Range
With Rng1
'Format the footnote reference as hidden text
.Font.Hidden = True
'Insert a number before the footnote reference and bookmark it
.Collapse wdCollapseStart
'To get the actual reference text, we need to cross-reference it!
.InsertCrossReference wdRefTypeFootnote, wdFootnoteNumber, i, False, False
.End = .End + 1
StrRef = .Fields(1).Result
.Fields(1).Delete
.Text = StrRef
.Text = i
.Style = wdStyleFootnoteReference
.Bookmarks.Add Name:="_FRef" & i, Range:=Rng1
End With
'Insert a number before the footnote content and bookmark it
With Rng2
'Format the footnote reference as hidden text
With .Words.First
If .Characters.Last Like "[ " & vbTab & "]" Then .End = .End - 1
.Font.Hidden = True
End With
'Insert a number before the footnote reference and bookmark it
.Collapse wdCollapseStart
.Text = StrRef
.Style = " Footnote Reference"
.Bookmarks.Add Name:="_FNum" & i, Range:=Rng2
End With
'Insert hyperlinks between the footnote references
.Hyperlinks.Add Anchor:=Rng1, SubAddress:="_FNum" & i
.Hyperlinks.Add Anchor:=Rng2, SubAddress:="_FRef" & i
'Restore the Rng1 footnote reference bookmark
.Bookmarks.Add Name:="_FRef" & i, Range:=Rng1
Next
'Update the statusbar
StatusBar = "Finished Processing " & .Endnotes.Count & " Endnotes" & .Footnotes.Count & " Footnotes"
End With
Set Rng1 = Nothing: Set Rng2 = Nothing
' Restore original Status Bar status
Application.DisplayStatusBar = SBar
' Restore original Track Changes status
ActiveDocument.TrackRevisions = TrkStatus
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub

Sub KillEndNoteFootNoteHyperLinks()
Dim SBar As Boolean ' Status Bar flag
Dim TrkStatus As Boolean ' Track Changes flag
Dim Rng1 As Range, Rng2 As Range, i As Long
' Store current Status Bar status, then switch on
SBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
' Store current Track Changes status, then switch off
With ActiveDocument
TrkStatus = .TrackRevisions
.TrackRevisions = False
End With
' Turn Off Screen Updating
Application.ScreenUpdating = False
With ActiveDocument
'Delete endnote/footnote hyperlinks from the MainStory
For i = .Hyperlinks.Count To 1 Step -1
With .Hyperlinks(i)
StatusBar = "Processing Hyperlink " & i
If .SubAddress Like "_ENum*" Then
.Range.Delete
ElseIf .SubAddress Like "_FNum*" Then
.Range.Delete
End If
End With
Next i
'Delete endnote hyperlinks from the EndnotesStory
If .Endnotes.Count > 0 Then
With .StoryRanges(wdEndnotesStory)
For i = .Hyperlinks.Count To 1 Step -1
StatusBar = "Processing Endnote Hyperlink " & i
With .Hyperlinks(i)
If .SubAddress Like "_ERef*" Then .Range.Delete
End With
Next i
End With
End If
'Delete footnote hyperlinks from the FootnotesStory
If .Footnotes.Count > 0 Then
With .StoryRanges(wdFootnotesStory)
For i = .Hyperlinks.Count To 1 Step -1
StatusBar = "Processing Footnote Hyperlink " & i
With .Hyperlinks(i)
If .SubAddress Like "_FRef*" Then .Range.Delete
End With
Next i
End With
End If
'Process all endnotes
For i = 1 To .Endnotes.Count
'Update the statusbar
StatusBar = "Processing Endnote " & i
'Define two ranges: one to the endnote reference the other to the endnote content
Set Rng1 = .Endnotes(i).Reference
Set Rng2 = .Endnotes(i).Range.Paragraphs.First.Range
'Format the endnote reference as visible text
Rng1.Font.Hidden = False
Rng2.Words.First.Font.Hidden = False
Next
'Process all footnotes
For i = 1 To .Footnotes.Count
'Update the statusbar
StatusBar = "Processing Footnote " & i
'Define two ranges: one to the footnote reference the other to the footnote content
Set Rng1 = .Footnotes(i).Reference
Set Rng2 = .Footnotes(i).Range.Paragraphs.First.Range
'Format the footnote reference as visible text
Rng1.Font.Hidden = False
Rng2.Words.First.Font.Hidden = False
Next
'Update the statusbar
StatusBar = "Finished Processing " & .Endnotes.Count & " Endnotes" & .Footnotes.Count & " Footnotes"
End With
Set Rng1 = Nothing: Set Rng2 = Nothing
' Restore original Status Bar status
Application.DisplayStatusBar = SBar
' Restore original Track Changes status
ActiveDocument.TrackRevisions = TrkStatus
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub

Sub HLnkNoteRefs()
Dim Fld As Field, StrTgt As String, Rng As Range, StrRef As String
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
For Each Fld In ActiveDocument.Fields
With Fld
If .Type = wdFieldNoteRef Then
StrTgt = ActiveDocument.Bookmarks(Split(Trim(.Code), " ")(1)).Range.Characters.First.Hyperlinks(1).SubAddress
StrRef = .Result
Set Rng = .Code
With Rng
While .Fields.Count = 0
.Start = .Start - 1
Wend
.Collapse wdCollapseStart
.Hyperlinks.Add Anchor:=Rng, SubAddress:=StrTgt, TextToDisplay:=StrRef
.End = .End + 1
.Hyperlinks(1).Range.Font.Superscript = True
End With
.Result.Font.Hidden = True
End If
End With
Next
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
End Sub

To make this process automatic, you could insert:
Call HLnkNoteRefs
after the final:
End With
in the HyperLinkEndNoteFootNotes macro.

Sub KillHLnkNoteRefs()
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
With Fld
If .Type = wdFieldNoteRef Then
.Result.Font.Hidden = False
End If
End With
Next
End Sub

To make this process automatic, you could insert:
Call KillHLnkNoteRefs
after the final:
End With
in the KillEndNoteFootNoteHyperLinks macro.

For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
 
Joined
Nov 16, 2016
Messages
2
Reaction score
0
Thank you for the response.

I am not an IT-expert. Therefore, I will discuss it with such one.

Thanks again for your help.

BR, Soeren
 
Joined
Jan 24, 2017
Messages
6
Reaction score
0
Thank you Mr. Edstein.

I have a similar problem (losing Endnotes) by converting doc to html. Do you have a similar macro for solving this problem?.

Thanks again for your help.

Samy
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
578
Reaction score
50
Did you try the macro I posted before converting the document to html? The resulting output preserves the links between the text and endnotes in my testing of the HTML file.
 
Joined
Jan 24, 2017
Messages
6
Reaction score
0
Did you try the macro I posted before converting the document to html?

Sorry, I could not find the macro converting the document to html? Please send me the Link.

I apologize for not being an IT expert (like Soeren), but not the English language.

I have no problem with the old-version of your macro (HyperlinkEndNotesFootNotes) for converting the document to pdf [by setting Style = "Endnote Reference" into Style = "Endnotenzeichen" (in German Language)]. After converting are all my 709 clickable endnotes in Doc-document (Word 2010) also clickable in PDF-document. [But by debuging in your new-version its stop by StrRef = .Fields(1).Result.]

Thanks again for your help.

Samy
 
Joined
Jan 24, 2017
Messages
6
Reaction score
0
It is not understandable that microsoft has been unable for a decade to convert doc to pdf and html file so that the endnotes are also converted.
 
Joined
Jan 24, 2017
Messages
6
Reaction score
0
Did you try the macro I posted before converting the document to html? The resulting output preserves the links between the text and endnotes in my testing of the HTML file.

Supplement: Sorry, I forgat to give you a direct answer of your question.

Yes! I tryed to convert the document to html (in the dokument-version after converting to pdf with your macro). But it dosent Work. I can send you the output, if you send me your email adress.

I am not an IT expert, but i think a macro for converting the document to html, must have similar strucktur as your macro for converting the document to pdf. Since by pdf and html must the endotes defined as hyperlinks. A macro for converting the document (with endnots) to html would be very importent for the e-book import.

Thanks for your commitment.

Samy
 
Last edited by a moderator:

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
578
Reaction score
50
Your assertion that endnotes are not converted when a document is saved to pdf or html is false - they are saved with the file in both formats and that has always been the case.

I don't know what you're doing but, as I already said, the macro works fine when run on a document that then gets saved in html format - just as it does when the file is saved in the pdf format - the html file ends up with working hyperlinks between the endnotes and body content.
 
Joined
Jan 24, 2017
Messages
6
Reaction score
0
Hello, Your assertion is absolutely right. Allow me to explain what my problem is:

My Documentation [written by Word 2010 and save as doc (not docx)] ist just 272 page lang but has over 700 endnotes and over 2000 (mainly internally) hyperlinks. All endotes are perfectly clickabel after converting to pdf with your macro (with a list of 709 endnotes-references at the end of the doc).

But if I try to convert the document to html (in the doc version after converting with your macro) my Word 2010 crashes permanently. The endotes are then neither clickabel in the crash down html-Output (21 Mb) nor in the crash down html-filtered-Output (3,2 Mb) and there exist no list of endnotes-references.

As you have described, your macro works excellent without toppling if I convert only a part of my Documentation (first chapter with 210 endnots) to html. This fact demonstrates that the word 2010 is capable of convert documents with numerous endnotes and hyperlinks in pdf but not in html.

My problem is that I can not divide my documentation into smaller parts. This is because the internally distributed hyperlinks (cross-references) in a chapter that refer to sections in other chapters would not be retrievable.

Do you have an idea how I can solve my problem. Perhaps the conversion with a stronger office would solve this problem.

Thanks again for your commitment.

Samy
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
578
Reaction score
50
Have you tried repairing the Office installation (via Start > Windows Control Panel > Programs > Programs & Features > Microsoft Office (version) > Change > Repair)?

It's also possible the document has acquired some of corruption. Corrupt documents can often be 'repaired' by inserting a new, empty, paragraph at the very end, copying everything except that new paragraph to a new document based on the same template (headers & footers may need to be copied separately), closing the old document and saving the new one over it.

Similarly, corrupt tables (which might also cause such problems but won't be repaired by the above approach) can often be 'repaired' by:
• converting them to text and back again;
• cutting & pasting them to another document that you save the document in RTF format, which you then close then re-open before copying them back to the source document; or
• saving the document in RTF format, closing the document then re-opening it and re-saving in the doc(x) format.

Changing Office versions is unlikely to make any difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top