View Single Post
 
Old 08-02-2016, 08:56 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
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

The following macro will copy each paragraph in the current document, that contains the word or phrase entered, to a new document. http://www.gmayor.com/installing_macro.htm
Code:
Sub GetParas()
Dim oDoc As Document
Dim oRng As Range
Dim strKeyWord As String
    strKeyWord = InputBox("Enter the word to find")
    If strKeyWord = "" Then GoTo lbl_Exit
    Set oRng = ActiveDocument.Range
    Set oDoc = Documents.Add
    With oRng.Find
        Do While .Execute(FindText:=strKeyWord, _
                          MatchCase:=False, _
                          MatchWholeWord:=True)
            oDoc.Range.InsertAfter oRng.Paragraphs(1).Range.FormattedText
            oRng.Collapse 0
        Loop
    End With
lbl_Exit:
    Exit Sub
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