View Single Post
 
Old 09-24-2019, 08:50 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote