Results 1 to 6 of 6

Thread: Find Word then Highlight Entire Paragraph and or Sentence Around That Word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Question Find Word then Highlight Entire Paragraph and or Sentence Around That Word

    Need help improving this code to find a word/term, then highlight (yellow) the whole sentence containing that word or if it is easier to accomplish: highlighting the whole paragraph where that word exists would also be awesome!

    Can be 2 separate chunks of code or maybe it's just a matter of changing a couple of things to make it go from only doing a SENTENCE vs. doing a PARAGRAPH.

    I found refs of maybe using a "paragraph.range.select" and also found a note that advised these "start" and "end" terms to select a paragraph.. but not sure how to achieve this? Somewhat of a novice.
    Selection.StartOf Unit:=wdParagraphm
    Selection.MoveEnd Unit:=wdParagraph

    Here's what I'm using now to FIND a word/term and do some highlighting but it is not highlighting the whole sentence (nor) whole paragraph.. perhaps it can be improved upon to work as desired or if not - I'm happy to trash it and use something better!

    Sub Highlight_WordN()
    'THIS FINDS A SPECIFIED TERM AS NOTED IN QUOTES BELOW AND HIGHLIGHTS IT IN YELLOW
    'IT HIGHLIGHTS SEVERAL OF THE WORDS AROUND IT BUT DOES NOT QUITE PICK UP THE FULL PARAGRAPH I'M LOOKING TO HIGHLIGHT
    'NEED TO EDIT IT A BIT TO BE MORE INCLUSIVE
     
    Dim sFindText As String
    'Start from the top of the document
     Selection.HomeKey wdStory
     
    sFindText = "Contractor Shall"
    Selection.Find.Execute sFindText
    Do Until Selection.Find.Found = False
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
            Selection.range.HighlightColorIndex = wdYellow
            Selection.MoveRight
            Selection.Find.Execute
    Loop
    End Sub
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •