![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
Is there any way to search for a particular word or phrase in Word 2010 and highlight the entire paragraph where it is found? I want to copy all the highlighted paragraphs that result from the search and paste them into a new Word 2010 document. Thank you very much! Last edited by Charles Kenyon; 09-26-2019 at 10:13 AM. Reason: Change title to give better info about question and mark as solved |
|
#2
|
|||
|
|||
|
There are no tools built into Word to accomplish this without macros.
|
|
#3
|
|||
|
|||
|
thanks for your answer, should I ask the question in the Word VBA forum then?
Thanks again |
|
#4
|
||||
|
||||
|
I am sure I did something very similar recently, but I cannot spot where I posted it, so the following will work. Change 'Word or phrase' as appropriate.
Code:
Sub Macro1()
Const strFind As String = "Word or phrase"
Dim oRng As Range, oTargetRng As Range
Dim oSource As Document, oTarget As Document
Set oSource = ActiveDocument
Set oTarget = Documents.Add
Set oRng = oSource.Range
With oRng.Find
Do While .Execute(findText:=strFind)
oRng.Start = oRng.Paragraphs(1).Range.Start
oRng.End = oRng.Paragraphs(1).Range.End
'oRng.HighlightColorIndex = wdYellow
Set oTargetRng = oTarget.Range
oTargetRng.Collapse 0
oTargetRng.FormattedText = oRng.FormattedText
oTargetRng.InsertParagraphAfter
oRng.Collapse 0
Loop
End With
Set oSource = Nothing: Set oTarget = Nothing
Set oRng = Nothing: Set oTargetRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#5
|
|||
|
|||
|
whoah!! THANKS A TON!!!
|
|
| Tags |
| highligh, search, word 2010 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| reverse order of paragraphs, word 2010 | moorea21 | Word VBA | 1 | 08-02-2018 03:47 AM |
Macro to highlight wildcard phrase, copy and paste into new doc.
|
MaryTom | Word VBA | 2 | 05-18-2018 04:23 PM |
Macro to hide all paragraphs that do not have the found result
|
jplat | Word VBA | 1 | 09-10-2017 09:13 PM |
issue with highlight macro word 2010
|
jamesnavoy | Word VBA | 2 | 01-29-2017 08:32 AM |
Macro to highlight text between 2 points in word 2010
|
jsilva1950 | Word VBA | 2 | 04-25-2013 12:21 AM |