Something like this:
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oDict
Dim oDocNotes As Document, oDocText As Document
Dim oRng As Range
Dim strNote As String
Dim oNote As Endnote
'Create a dictionary containing the defined endnote text. Note references "must" be unique.
Set oDict = CreateObject("Scripting.Dictionary")
Set oDocNotes = Documents.Open("C:\Users\Maxey\Desktop\befor run vb2.txt", , , False, , , , , , , , False)
Set oRng = oDocNotes.Range
With oRng.Find
.Text = "(endendnote)(*)(startendnote)"
.MatchWildcards = True
.Replacement.Text = "\2"
While .Execute(Replace:=wdReplaceOne)
strNote = oRng.Paragraphs(1).Range.Text
strNote = Trim(Replace(strNote, oRng.Text, ""))
oDict.Add oRng.Text, strNote
oRng.Collapse wdCollapseEnd
Wend
End With
oDocNotes.Close wdDoNotSaveChanges
'Open the text document and replace the flags with the matching dictionary item
Set oDocText = Documents.Open("C:\Users\Maxey\Desktop\befor run vb1.txt")
Set oRng = oDocText.Range
With oRng.Find
.Text = "(endendnote)(*)(startendnote)"
.MatchWildcards = True
.Replacement.Text = "\2"
While .Execute(Replace:=wdReplaceOne)
Set oNote = ActiveDocument.Endnotes.Add(oRng, oRng.Text, oDict.Item(oRng.Text))
If Asc(oNote.Range.Characters.Last) = 13 Then
oNote.Range.Characters.Last.Delete
End If
oRng.Delete
Wend
End With
lbl_Exit:
Exit Sub
End Sub
P.S. before is spelled with an ending e