View Single Post
 
Old 03-15-2019, 10:07 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You replace the original loop with this one e.g. as follows
checkphrases.docx sholuld have each word or phrase to find in a new paragraph (with no empty paragraphs).



Code:
Sub ComparePhraseList()
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim i As Integer
Dim oPara As Range


sCheckDoc = "c:\path\checkphrases.docx"  'Change to the path where the document is located.
   Set docCurrent = Selection.Document
    Set docRef = Documents.Open(sCheckDoc)
    docCurrent.Activate
    Options.DefaultHighlightColorIndex = wdYellow

    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Highlight = True
        .Replacement.Text = "^&"
        .Forward = True
        .Format = True
        .MatchWholeWord = True
        .MatchCase = True
        .MatchWildcards = False
    End With

    For i = 1 To docRef.Paragraphs.Count
        Set oPara = docRef.Paragraphs(i).Range
        oPara.End = oPara.End - 1
        With Selection.Find
            .Wrap = wdFindContinue
            .Text = oPara.Text
            .Execute Replace:=wdReplaceAll
        End With
    Next i

    docRef.Close
    docCurrent.Activate
    Set docRef = Nothing
    Set docCurrent = Nothing
    Set oPara = Nothing
   
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote