View Single Post
 
Old 01-31-2019, 01:04 AM
coolio2341 coolio2341 is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Jan 2019
Posts: 4
coolio2341 is on a distinguished road
Default Find several words in document, copy paragraph and create new document

Hello MS Office community.


I am trying create a vba script that will search for multiple words, copy the paragraph which has that word and will insert into a new document. I found the following scripts which works amazingly but with one text only. How can I modify this script, so instead of only one search to have multiples, array of words to search for. Any help will be greatly appreciated.


The script below will search for "1945" and will copy the paragraph that contains "1945" and insert into new document. How to make do the same but for several texts example 1945, 1946, 1947 etc


Thank you in advance



================================


Sub CopyParas
Selection.Find.ClearFormatting
With Selection.Find
.Text = "1945"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute
Selection.StartOf Unit:=wdParagraph
Selection.MoveEnd Unit:=wdParagraph
sBigString = sBigString + Selection.Text
Selection.MoveStart Unit:=wdParagraph
Loop
Documents.Add DocumentType:=wdNewBlankDocument
Selection.InsertAfter (sBigString)
End Sub






------------------------------------------------------------
Reply With Quote