Quote:
Originally Posted by gmayor
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
|
This is another really good one! Thank you for taking the time :]
I was curious if we could iron out some things with this one. Just a few things that leave it wanting:
1.) Would it be possible to make so the macro functions as a cut-and-paste rather than a copy-and-paste? It's essential for reducing the page amount of the first document being cut-and-pasted from
2.) I noticed the new document has copies of certain paragraphs that used the key word more than once. So a paragraph that said 'game' three times, the new document the macro made has three copies of that paragraph next to each other.
3.) This one isn't so bad, but is it possible to make the new document have spaces between the paragraphs? They all got placed directly beneath one another instead of having gaps between them, as if it's all one giant super-wall of text ^ ^'
I appreciate your help thus far whether we can do this or not :]