![]() |
|
#2
|
||||
|
||||
|
The following will write sentences containing 'the supplier', regardless of case, to a new document.
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 25 Sep 2019
Dim oSource As Document
Dim oTarget As Document
Dim oRng As Range, oTargetRng As Range
Set oSource = ActiveDocument
Set oTarget = Documents.Add
Set oRng = oSource.Range
With oRng.Find
Do While .Execute(findText:="the supplier")
oRng.Start = oRng.Sentences(1).Start
oRng.End = oRng.Sentences(1).End
Set oTargetRng = oTarget.Range
oTargetRng.Collapse 0
oTargetRng.FormattedText = oRng.FormattedText
oRng.Collapse 0
Loop
End With
Set oRng = Nothing
Set oTargetRng = Nothing
Set oSource = Nothing
Set oTarget = 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 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Renaming several strings of text by their pattern
|
noname91 | Word | 10 | 01-05-2017 05:46 PM |
| Extracting lines containing specific word. | S.Allen | Word VBA | 1 | 03-27-2015 10:50 PM |
| Extracting specific rows | sbdk82 | Excel | 4 | 09-07-2014 10:24 PM |
Need help extracting specific text from one doument to another with macro/VBA.
|
zsmithku | Word | 1 | 04-15-2011 03:46 PM |
update style of all strings available between two specific strings
|
vikrantkale | Word | 1 | 03-28-2011 06:13 PM |