View Single Post
 
Old 05-16-2014, 06:34 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 Insert input box into macro to allow user to define search term

I would like to adapt this code so that the user is prompted by an input box to enter text which is then searched for. At the moment, it says "Las Vegas" and I am editing the code manually every time I want to change it and search for a different item. I'd like to be able to enter any text in a box when using Word. Ideally, I would have a keyboard shortcut to open the input box, enter text, press return and the macro would produce its result. Grateful for any help, please. Thanks.

Code:
Sub CreateSummary()
'
' CreateSummary Macro

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Las Vegas"
.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