I am interested in creating a Word macro that can be used to highlight particular text that is marked with track changes.
For example, the following code can highlight all text that is marked with track changes:
Code: Select all
Sub Highlight_Tracked_Changes()
Dim rev As Revision
' Turn off track changes
ActiveDocument.TrackRevisions = False
' Show revisions
With ActiveWindow.View.RevisionsFilter
.Markup = wdRevisionsMarkupAll
.View = wdRevisionsViewFinal
End With
For Each rev In ActiveDocument.Revisions
rev.Range.HighlightColorIndex = wdYellow
Next rev
End Sub
Code: Select all
Sub Highlight_Words()
Const strWorkbook As String = "C:\Users\Downloads\WordList.xlsx" 'The workbook path
Const strRange As String = "Wordlist"
Dim Arr() As Variant, lngRows As Long, oRng As Range, strFind As String, bWC As Boolean
Arr = xlFillArray(strWorkbook, strRange)
For lngRows = 0 To UBound(Arr, 2)
strFind = Arr(0, lngRows)
Set oRng = ActiveDocument.Range
With oRng.Find
.MatchCase = False
bWC = Arr(2, lngRows) = "T" 'assumes named range includes at least 3 columns with no empty cells
.MatchWildcards = bWC
Do While .Execute(FindText:=strFind)
oRng.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
Next lngRows
lbl_Exit:
Exit Sub
End Sub
Private Function xlFillArray(strWorkbook As String, _
strRange As String) As Variant
Dim RS As Object
Dim CN As Object
Dim iRows As Long
strRange = strRange & "]"
Set CN = CreateObject("ADODB.Connection")
CN.Open ConnectionString:="Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strWorkbook & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=NO;IMEX=1"""
Set RS = CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM [" & strRange, CN, 2, 1
With RS
.MoveLast
iRows = .RecordCount
.MoveFirst
End With
xlFillArray = RS.GetRows(iRows)
If RS.State = 1 Then RS.Close
Set RS = Nothing
If CN.State = 1 Then CN.Close
Set CN = Nothing
lbl_Exit:
Exit Function
End Function