View Single Post
 
Old 06-06-2014, 09:12 AM
Hoxton118 Hoxton118 is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Mar 2014
Posts: 21
Hoxton118 is on a distinguished road
Default VBA code to compile one document based on multiple search terms

I have the following code which allows me to select a search term and create a single new document which includes only those paragraphs containing the search term. I enter the search term in an input box.

Is there a way of getting the code to use a list of search terms from another file (whether Excel or Word) so that, rather than entering each search term individually, it will do multiple search terms at once - all results ending up in one document.

Another solution would be to enable a Boolean search in the input box, so that I could ask for multiple search terms there.

I would be very grateful for any help. Thanks.

Code:
Sub CreateSummary()
'
' CreateSummary Macro

Selection.Find.ClearFormatting
With Selection.Find
 .Text = InputBox("Type search term and press Enter.")
.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