Microsoft Word Macro - Adding Footnote to Specific Text

leever

New Member
Joined
Jun 29, 2023
Messages
11
Hello. I am trying to create a macro that adds footnotes in a Word document when there is specific text. For example, I have a list of names and addresses with common occurring typos.

1735612244528.png


From the data, the text that I would want footnoted are “SMith”, “NEw”, “ORLeans”.

This is the code I have but it is not giving me what I want.
---
Public Sub HighlightMultipleWords()
Application.ScreenUpdating = False

Dim sArr() As String
Dim rTmp As Range
Dim x As Long

Set rTmp = ActiveDocument.Range
sArr = Split("SMith”, “NEw”, “ORLeans ")
For x = 0 To UBound(sArr)

With rTmp.Find
.Text = sArr(x)
.Replacement.Text = sArr(x)
ActiveDocument.Footnotes.Add rTmp, Text:="Written in data"
End With
Next

End Sub
---

Any help would be greatly appreciated. Thank you!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
First, correct the line to the following.
VBA Code:
sArr = Split("SMith,NEw,ORLeans", ",")
And then keep fighting.

Artik
 
Upvote 0
First, correct the line to the following.
VBA Code:
sArr = Split("SMith,NEw,ORLeans", ",")
And then keep fighting.

Artik
Thank you Artik. I can't get the footnote numbers to come after the words. "123" shows up after the block of text. Any further tips would be greatly appreciated. Thank you.
 
Upvote 0
Try this
VBA Code:
Sub HighlightMultipleWords_2()
    Dim sArr() As String
    Dim rTmp As Range
    Dim x As Long

    Application.ScreenUpdating = False

    sArr = Split("SMith,NEw,ORLeans", ",")

    For x = 0 To UBound(sArr)

        Set rTmp = ActiveDocument.Range

        With rTmp.Find
            .Text = sArr(x)
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .MatchCase = True

            Do While .Execute
                ActiveDocument.Footnotes.Add Range:=rTmp, Text:="Note to the phrase '" & sArr(x) & "'" 
                rTmp.Collapse Direction:=wdCollapseEnd
            Loop

        End With

    Next x

    Application.ScreenUpdating = True
End Sub
Artik
 
Upvote 0

Forum statistics

Threads
1,225,190
Messages
6,183,457
Members
453,160
Latest member
DaveM_26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top