Actually in doesn't do exactly as you asked because for some reason the code I posted wasn't the code I wrote. I believe it if Contractor shall is found in the second
or subsequent sentence of a paragraph then you only want from that sentence on to the end of the paragraph highlighted.
It differed where Graham highlighted the sentence containing the found text where I highlighted the paragraph of the found text.
Sub Highlight_WordN()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="Contractor Shall")
oRng.Start = oRng.Sentences(1).Start
oRng.End = oRng.Paragraphs(1).Range.End
oRng.HighlightColorIndex = wdYellow
oRng.Collapse 0
Loop
End With
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
Note: Word doesn't have a clear idea what a sentence is all about. Where the code above would highlight. Blah,blah. [John Smith the contractor shall blah. Blah blah]
it would process Blah, blah. Mr. [Smith the contractor shall blah. Blah, blah.
because Word confuses the period after Mr. as a sentence stop.
No (1) is not one paragraph to the right. It is the first paragraph in the ranges paragraph collection. So when the range is defined as a word or snippet in a paragraph the range.Paragraphs(1) is that ranges parent paragraph.
Collapse 0 is simple short for Collapse wdCollapseEnd where wdCollapseEnd is constant with the value = 0
You collapse the range so you don't get stuck in a loop finding the same thing over and over again.
lbl_Exit:
Exit Sub
Is just my style that my good friend Graham liked and adapted.
It doesn't serve much purpose other that to tell me that I have at least thought more than absently about what the code does and serves as an exit loop:
On Error GoTo lbl_Err
Err.Raise 6
lbl_Exit:
Exit Sub
lbl_Err:
Msgbox Err.Number & " " Err.Description
Resume lbl_Exit
End Sub