I am trying to proofread scientific papers by finding and highlighting common punctuation and spacing errors (such as double spaces, incorrect spacing around punctuation marks, etc.). I am using Word 2010.
The following code works for Word documents that do not have Track Changes turned on. It highlights instances of the strings contained in TargetList in red:
Sub HighlightTargets2()
Dim range As range
Dim i As Long
Dim TargetList
TargetList = Array(" ", " ,", " .", " ?", " :", " ;", " -", " –", " —", "- ", "– ", "— ", ",,", "..", "::", ";;", "??", ",.", ".,", ",?", "?,", "?.", ".?", ";:", ":;", ";,", ";.", ".;", ".;", "^$(", "^$ )", "( ^$", "^#(", "^# )", ")^ #", "( ^#") ' put list of terms to find here
For i = 0 To UBound(TargetList)
Set range = ActiveDocument.range
With range.Find
.Text = TargetList(i)
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute(Forward:=True) = True
range.HighlightColorIndex = wdRed
Loop
End With
Next
End Sub
I only need to check for such errors in the final view of the document. However, this macro takes "deleted" (as in, deleted but changes not yet accepted) characters as still being present in the document.
Consider this example (ignore the yellow highlights).
I split the original sentence by adding a period and deleting the semicolon. Thus, in Final: Show Markup, the inserted period and the deleted semicolon appear together (.;). Even if I run the macro while on "Final" view (not "Final: Show Markup"), the .Find method will take such "deleted" characters as still being in the text.
The following effect happens.
Wrong Highlight
One possible workaround is to open another instance of Word, copy and paste all the text from the file (after selecting "Final") and running the macro on the new instance of Word. Then, I'd have to look for the highlighted errors on the new instance of Word and manually fix them on the other.
Is there a way to make the .Find method only search on text that appears when viewing the document in "Final" view and ignore text that was deleted while Track Changes was on?