PDA

View Full Version : VBA code to highlight text between pages in word document



srini4547
07-06-2016, 12:29 AM
Hi

Could some one help me on below requirement

i need to highlight text in specific page in word document

e.g: Suppose my word document has 100 pages and "application_code" is the search string i wanted to highlight in only between pages no's 10 -15


please help me on this

Thanks in advance

gmayor
07-06-2016, 08:04 AM
Set a range from the start of Page 10 to the end of the document and stop processing when the found text is on a page after 15


Dim oRng As Range
Selection.HomeKey
Set oRng = ActiveDocument.Range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, name:="10"
oRng.Start = Selection.Start
With oRng.Find
Do While .Execute(FindText:="application_code ")
If oRng.Information(wdActiveEndPageNumber) > 15 Then
Exit Sub
Else
oRng.HighlightColorIndex = wdTurquoise
End If
oRng.Collapse 0
Loop
End With