1

Book endnotes often forgo superscript numbers for page numbers. E.g., instead of

Abe Lincoln was assassinated with a pistol.^33
                   :
33. A single-shot derringer pistol.

books by several authors write

Abe Lincoln was assassinated with a pistol.
                   :
Page 297. Abe Lincoln was shot single-shot derringer pistol.

Word doesn't have this feature, so I believe it would have to be a Macro. I came up with simple code below that loops through all of the endnotes and adds

"Page ???. "

before each endnote, but what does "???" need to be to correctly insert the page number in my manuscript that the citation's located on?

Sub RedefineExistingEndNotes()
    Dim fn As Endnote
    For Each fn In ActiveDocument.Endnotes
        fn.Range.Paragraphs(1).Range.Font.Reset
        fn.Range.Paragraphs(1).Range.Characters(1).InsertBefore "Page" & "???" & " - "
    Next fn
End Sub
buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52
  • It's not clear how you'd tag them correctly even if you were doing it manually? Your second example has nothing to indicate the presence of an endnote. – Tim Williams Jan 21 '16 at 07:28
  • @Tim, the approach would be to add an endnote as usual but then change the endnote properties to hide them by using invisible text or equivalent. – buttonsrtoys Jan 21 '16 at 14:27
  • @buttonstoys: FWIW I deleted my Answer as (a) I hadn't tested it well enough and (b) the approach would need to find a way to hide the endnote marker without hiding its paragraph marker, and I am not sure that is possible. Apologies for the distraction. –  Jan 25 '16 at 08:06
  • @bibadia: no apology necessary. I liked how you hid the endnote superscript in the body of the text and will be employing that. I'm thinking that rather than hiding the endnote marker in the table, I'd convert it to a bullet. If that solves your hiding problem, please repost your solution and I'll +1 it. – buttonsrtoys Jan 25 '16 at 18:21
  • @buttonsrtoys: OK, will do. My main reason for attempting that approach was that you got to preserve the references, but whether that's useful or not depends on your publishing procedure. –  Jan 25 '16 at 18:34
  • @bibadia: Awesome, Thanks! Elaborating, the page number would be above the endnote, like a heading, so multiple notes on the same page would all be bulleted under a single page number heading. – buttonsrtoys Jan 25 '16 at 18:49

2 Answers2

2

Try the below VBA code:

Sub InsertPageNumberForEndnotes()

Dim endNoteCount As Integer
Dim curPageNumber As Integer

If ActiveDocument.Endnotes.Count > 0 Then

For endNoteCount = 1 To ActiveDocument.Endnotes.Count

Selection.GoTo What:=wdGoToEndnote, Which:=wdGoToAbsolute, Count:=endNoteCount
curPageNumber = Selection.Information(wdActiveEndPageNumber)
ActiveDocument.Endnotes(endNoteCount).Range.Select
ActiveDocument.Application.Selection.Collapse (WdCollapseDirection.wdCollapseStart)
ActiveDocument.Application.Selection.Paragraphs(1).Range.Characters(1).InsertBefore "Page " & CStr(curPageNumber) & " - "


Next
End If

End Sub
  • Wow! Great solution. This gets me over the biggest hurdle. Do you have a tweak that will hyperlink the inserted "Page 297" text back to its page? This is the default behavior of the tabulated endnote numbers. I'll be deleting the numbers now that I have the page numbers but am hoping to retain the hyperlink feature. – buttonsrtoys Jan 21 '16 at 14:24
1

An alternative might be to use PAGEREF fields and hide the endnote references, e.g.

Sub modifyEndNotes()
Const bookmarkText As String = "endnote"
Dim en As Word.Endnote
Dim rng As Word.Range
For Each en In ActiveDocument.Endnotes
  en.Reference.Bookmarks.Add bookmarkText & en.Index
  en.Reference.Font.Hidden = True
  Set rng = en.Range
  rng.Paragraphs(1).Range.Font.Hidden = True
  rng.Collapse WdCollapseDirection.wdCollapseStart
  rng.Text = "Page . "
  rng.SetRange rng.End - 2, rng.End - 2
  rng.Fields.Add rng, WdFieldType.wdFieldEmpty, "PAGEREF " & bookmarkText & en.Index & " \h", False
  'if necessary...
  'rng.Fields.Update
  en.Range.Font.Hidden = False
Next
Set rng = Nothing
End Sub

For a second run, you'd need to remove and re-insert the text and fields you had added.

Unfortunately, a further look suggests that it would be difficult, if not impossible, to hide the endnote references (in the endnotes themselves) without hiding the paragraph marker at the end of the first endnote para, which means that all the endnotes will end up looking like a single messy note. So I deleted this Answer.

However, the OP thought the approach could be modified in a useful way so I have undeleted. I can't re-research it right away but some possibilities might be to replace every endnote mark by a bullet (as suggested by the OP) or perhaps even something as simple as a space or a "-".

For example, something like this (which also hides the references using a different technique)...

Sub modifyEndNotes2()
' this version also formats the endnotes under page headings
Const bookmarkText As String = "endnote"
Dim en As Word.Endnote
Dim f As Word.Field
Dim i As Integer
Dim rng As Word.Range
Dim strSavedPage As String
strSavedPage = ""
For Each en In ActiveDocument.Endnotes
  en.Reference.Bookmarks.Add bookmarkText & en.Index
  Set rng = en.Range
  rng.Collapse WdCollapseDirection.wdCollapseStart
  If CStr(en.Reference.Information(wdActiveEndPageNumber)) <> strSavedPage Then
    strSavedPage = CStr(en.Reference.Information(wdActiveEndPageNumber))
    rng.Text = "Page :-" & vbCr & " - "
    rng.SetRange rng.End - 6, rng.End - 6
    rng.Fields.Add rng, WdFieldType.wdFieldEmpty, "PAGEREF " & bookmarkText & en.Index & " \h", False
    rng.Collapse WdCollapseDirection.wdCollapseEnd
  Else
    rng.Text = "- "
  End If
Next
If ActiveDocument.Endnotes.Count > 1 Then
  ActiveDocument.Styles(wdStyleEndnoteReference).Font.Hidden = True
Else
  ActiveDocument.Styles(wdStyleEndnoteReference).Font.Hidden = False
End If
Set rng = Nothing
End Sub

In the above case, notice that there is only one link to each page, that formatting might be needed to make it obvious that it is a link, and so on.

  • Very nice approach, though there seams to be a bug when running from Word 2007: all endnotes in the endnote table get hidden except for one? So, not just the endnote number is hidden, but the text as well. – buttonsrtoys Jan 24 '16 at 17:40
  • I edited my Answer to add a slightly different approach that does some of the stuff you just mentioned. IMO further refinement is really up to you. –  Jan 27 '16 at 11:20