Hello All,
I would like to be able to select / highlight a block of text and use the following find and highlight macro to step through the selected text and when each instance of a specified word is found it highlights the line.
A while ago Greg Maxey helped me out with a macro which I have modified to suit my needs and works well, however the macro searches for the specified word within the whole document and I would like to restrict its operation to just to the text that has been selected / highlighted.
Can someone please tell me what changes need to be made to the following macro so that it is restricted to the selected text only?
Sub FindWordHighlightLine()
'http://www.vbaexpress.com/forum/showthread.php?t=39296
' Code written by Greg Maxey
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.Text = InputBox("Text to highlight")
Do While .Execute
.Wrap = wdFindStop
.Forward = True
myRange.Select
ActiveWindow.ScrollIntoView Selection.Range
Select Case MsgBox("Do you want to highlight this line?", vbQuestion + vbYesNoCancel, "Highlight line")
Case vbYes
Selection.Bookmarks("\line").Select
With Selection.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorLightTurquoise
End With
Case vbNo
myRange.Collapse wdCollapseEnd
Case Else
GoTo lbl_Exit
End Select
Loop
End With
lbl_Exit:
Exit Sub
End Sub
Any help or pointers would be appreciated.
Regards,
Dave T