A few notes/questions:
- I got an error in FndRepRng on the array declarations. After I took out the "Const," it worked no problem.
- I guess because endnotes are automatically linked, it doesn't seem necessary to test each one to see if it's linked to the previous note. But with your macro, we've got a horizontal structure:
Const ArrFnd = Array("Findterm1", "Findterm2")
Const ArrRep = Array("Replaceterm1", "Replaceterm2")
This could get cumbersome. Is there any way to incorporate the vertical list approach in your macro?
Code fixed.
Endnotes are not linked - the part of the code you're referring to applies to headers and footers only.
If all you want to do is replace endnote text, you could use any of the following approaches:
Sub EndnoteFndRep1()
Dim i As Long, ArrFnd As Variant, ArrRep As Variant
ArrFnd = Array("Findterm1", "Findterm2", "Findterm3", "Findterm4")
ArrRep = Array("Replaceterm1", "Replaceterm2", "Replaceterm3", "Replaceterm4")
With ActiveDocument.StoryRanges(wdEndnotesStory).Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = True
For i = 1 To UBound(ArrRep)
.Text = ArrFnd(i)
.Replacement.Text = ArrRep(i)
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
Sub EndnoteFndRep2()
Dim i As Long, ArrFndRep As Variant
ArrFndRep = Array("Findterm1", "Replaceterm1", "|", "Findterm2", "Replaceterm2", _
"|", "Findterm3", "Replaceterm3", "|", "Findterm4", "Replaceterm4")
With ActiveDocument.StoryRanges(wdEndnotesStory).Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = True
For i = 1 To UBound(ArrFndRep) Step 3
.Text = ArrFndRep(i)
.Replacement.Text = ArrFndRep(i + 1)
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
Sub EndnoteFndRep3()
Dim i As Long, ArrFnd(3) As Variant, ArrRep(3) As Variant
ArrFnd(0) = "Findterm1"
ArrRep(0) = "Replaceterm1"
ArrFnd(1) = "Findterm2"
ArrRep(1) = "Replaceterm2"
ArrFnd(2) = "Findterm3"
ArrRep(2) = "Replaceterm3"
ArrFnd(3) = "Findterm4"
ArrRep(3) = "Replaceterm4"
With ActiveDocument.StoryRanges(wdEndnotesStory).Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = True
For i = 1 To UBound(ArrRep)
.Text = ArrFnd(i)
.Replacement.Text = ArrRep(i)
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
With the last one, note that the number included in the variable declaration must at least equal the number assigned to the last element.