Hello.
I have a MS Word document that I need to check against a table of terms contained in another MS Word document. Essentially, I need to highlight the phrases/words in the document that coincide with phrases/words contained in the table of terms. The table of terms is formatted like this:
duplicate line item
duplicate procedures
duplication of benefits
Durable Medical Equipment (DME)
durable medical equipment exceeds rental cost
durable medical equipment maximum frequency
As a first attempt, I tried the code below. The problem is that it highlights EVERY SINGLE WORD from the table of terms. As I explained, I only want to highlight the phrases/words that coincide exactly with the phrases/words from the table (although many of the entries are single words, as a matter of fact). I tried to modify the code but didn’t have any luck. Thanks in advance for whatever help/guidance you can give me.
Code:
Sub CompareWordList()
Dim sCheckDoc As String
Dim docRef As Document
Dim docCurrent As Document
Dim wrdRef As Object
sCheckDoc = "c:\checklist.doc"
Set docCurrent = Selection.Document
Set docRef = Documents.Open(sCheckDoc)
docCurrent.Activate
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Replacement.Text = "^&"
.Forward = True
.Format = True
.MatchCase = True
.MatchWildcards = False
End With
For Each wrdRef In docRef.Words
If Asc(Left(wrdRef, 1)) > 32 Then
With Selection.Find
.MatchWholeWord = True
.Wrap = wdFindContinue
.Text = wrdRef
.Execute Replace:=wdReplaceAll
End With
End If
Next wrdRef
docRef.Close
docCurrent.Activate
End Sub