View Single Post
 
Old 10-02-2019, 07:34 AM
poggyton poggyton is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2019
Posts: 3
poggyton is on a distinguished road
Default How to point a macro that highlights from a string of words at the footnotes rather than main doc

I came across most of a solution to what I am trying to accomplish in this thread https://www.msofficeforums.com/word-...-document.html

Quote:
Originally Posted by macropod View Post
Hi AtaLoss,

Try something based on:
Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "dog,cat,pig,horse,man"
For i = 0 To UBound(Split(StrFnd, ","))
  Set Rng = ActiveDocument.Range
  With Rng.Find
    .ClearFormatting
    .Text = Split(StrFnd, ",")(i)
    .Replacement.ClearFormatting
    .Replacement.Highlight = True
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
    .Execute Replace:=wdReplaceAll
  End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Note: Because I've set 'MatchAllWordForms = True', a Find for 'cat' or 'man' will also find & highlight 'cats' & 'men'. Apart from that, the matched words must be whole words. That means you don't need multiple expressions to capture the various forms of a given word.
The only problem I'm having is that this only highlights above the line text, not text within footnotes. I would prefer if it it only searched footnotes, but all text could also work. From my brief research I believe this has to do with the range being set, and I've been noodling around with the "Footnotes" object to try to change this with no success.

Thank you,

Poggyton
Reply With Quote