View Single Post
 
Old 09-26-2019, 12:16 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

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
P.S. Found it - https://www.msofficeforums.com/word-...t-strings.html
__________________
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