View Single Post
 
Old 11-22-2014, 11:13 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

Create a document with a single column table. Put one of the phrases in each cell (no blanks) save the document then put the name and path in the following macro in place of "C:\Path\Table.docx". Run the macro on your document with the phrases.

Code:
Sub Highlighting()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oCell As Cell
Dim oRng As Range
Dim rFindText As Range
Const sFname As String = "C:\Path\Table.docx"
    Set oDoc = ActiveDocument
    Set oChanges = Documents.Open(Filename:=sFname, Visible:=False)
    Set oTable = oChanges.Tables(1)
    For Each oCell In oTable.Range.Cells
        If Len(oCell.Range) > 2 Then
            Set oRng = oDoc.Range
            Set rFindText = oCell.Range
            rFindText.End = rFindText.End - 1
            With oRng.Find
                .ClearFormatting
                .Replacement.ClearFormatting
                Do While .Execute(FindText:=rFindText, _
                                  MatchWholeWord:=True) = True
                    oRng.HighlightColorIndex = wdBrightGreen
                Loop
            End With
        End If
    Next oCell
lbl_Exit:
    oChanges.Close 0
    Set oChanges = Nothing
    Set oDoc = Nothing
    Set oRng = Nothing
    Set rFindText = Nothing
    Exit Sub
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