Reputation: 2171
I am hoping to use a macro to replace the endnotes in a word document. Here is my situtation:
I have two word docs. Both documents have the exact same number of endnotes. One document is full of the correct body content, but has placeholders for the end notes. The other document has outdated content, but has the correct endnotes to to fill the placeholders in the first document.
I have setup a macro below that can loop through all of the endnotes in the correct file, and then opens the other document called "old.docx" below. I just dont know how to go about replacing the endnotes in old.docx with the value of ftstr (please see below).
Any help would be great!
Sub endnoteReplacer()
Dim ft As Endnote
Dim wrdApp As Object
Dim wrdDoc As Object
Dim r1 As Range, ftstr As String, mark
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
Set wrdDoc = wrdApp.Documents.Open("C:\Desktop\old.docx")
For Each ft In Word.ActiveDocument.Endnotes
ftstr = ft.Range.Text
wrdDoc.Endnotes(ft.Index).Range.Text = ftstr
Next ft
End Sub
Upvotes: 1
Views: 1672
Reputation: 19067
If I get you right you need this simple solution to add within your loop:
For Each ft In Word.ActiveDocument.Endnotes
ftstr = ft.Range.Text
'change value of corresponding footnote in old.docx to value of ftstr
'!! new line !!
wrdDoc.Endnotes(ft.Index).Range.Text = ftstr
Next ft
But I assumed that you need to change endnotes(1) to endnotes(1), 2 to 2, etc...
Upvotes: 1