Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2014, 06:34 AM
Hoxton118 Hoxton118 is offline Insert input box into macro to allow user to define search term Windows 7 32bit Insert input box into macro to allow user to define search term Office 2010 32bit
Novice
Insert input box into macro to allow user to define search term
 
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
  #2  
Old 05-16-2014, 12:38 PM
fumei fumei is offline Insert input box into macro to allow user to define search term Windows 7 64bit Insert input box into macro to allow user to define search term Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Code:
 .Text = InputBox("Type City and press Enter.")


Comments:
declare your variables!
if the Selection point is ahead of the text you enter, it will NOT find it. If you want to go through the entire document use the document range, rather than Selection.

Do you actually want to create a new document for every found instance of your text string?
Reply With Quote
  #3  
Old 05-17-2014, 05:43 AM
Hoxton118 Hoxton118 is offline Insert input box into macro to allow user to define search term Windows 7 32bit Insert input box into macro to allow user to define search term Office 2010 32bit
Novice
Insert input box into macro to allow user to define search term
 
Join Date: Mar 2014
Posts: 21
Hoxton118 is on a distinguished road
Default

Quote:
Originally Posted by fumei View Post

Do you actually want to create a new document for every found instance of your text string?
Thanks for the reply. No, the macro creates one file containing all paragraphs including the search term.
Reply With Quote
  #4  
Old 05-19-2014, 02:03 AM
Hoxton118 Hoxton118 is offline Insert input box into macro to allow user to define search term Windows 7 32bit Insert input box into macro to allow user to define search term Office 2010 32bit
Novice
Insert input box into macro to allow user to define search term
 
Join Date: Mar 2014
Posts: 21
Hoxton118 is on a distinguished road
Default

Many thanks - this worked a treat. Best wishes.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert input box into macro to allow user to define search term Insert input box into macro to allow user to choose multiple text entries Hoxton118 Word VBA 6 04-03-2014 12:12 AM
Insert input box into macro to allow user to define search term User input to a variable on the document dsm1995gst Word VBA 1 09-03-2013 03:43 PM
Insert input box into macro to allow user to define search term Replacing text with user input.?.?.? brad1977 Word 3 11-20-2012 10:20 AM
Insert input box into macro to allow user to define search term Restricting User Input on a TextBox (and setting focus) joatmon Excel Programming 1 06-05-2012 03:01 PM
Look up an array based on user input johnsmb Excel 2 01-07-2011 01:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft