title: Replacing reference with endnote text in Word
body: <p>I have a text in Word that includes references (1,2,3,...) to endnotes. There are multiple references to the same endnote (for example there are several 1s) created by cross-referencing.</p>
  
  <p>I would like to replace all references with endnote text. </p>
  
  <p>On the internet I have found a code that does that. The problem is that if there are several references to the same endnote, only reference whose position is the first in the document gets to be replaced with text (for example only the first 1, other 1s don't). </p>
  
  <p>I need help how to replace all references with the appropriate endnote text. </p>
  
  <pre><code>Sub endnotes2()
    Dim Note As Endnote
    Dim NoteReference As String
    Dim NoteText As String
  
    For Each Note In ActiveDocument.Endnotes
      With Note
        NoteText = .Range.Text
        NoteReference = .Index
        Call Selection.SetRange(.Reference.End, .Reference.End)
        Selection.Font.Superscript = True
        Selection.TypeText (NoteText)
        Selection.Font.Superscript = False
      End With
    Next Note
  
    Do While ActiveDocument.Endnotes.Count &gt; 0
      Call ActiveDocument.Endnotes(1).Delete
    Loop
  
   Selection.Find.ClearFormatting
    Selection.Find.Font.Superscript = True
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Superscript = False
    With Selection.Find
      .Text = ""
      .Replacement.Text = " (^&amp;)" 'The ^&amp; here refers to the "found text", so if we found "abc" we will replace it with "(abc)"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
  End Sub
  </code></pre>