Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

MS Word 2010 macro help


(!)

technical_editor's Avatar
technical_editor technical_editor is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Sep 2011
Experience: Advanced
29-Sep-2011, 01:24 PM #1
MS Word 2010 macro help
I need a macro that searches for a specific list of words using the find function in MS Word. For example, if I had a document with 100 recipes in it and I needed to find all the locaitons within the file that had the word flour, oil, or egg in it, this macro would go through and take me to the location of these words. I edit a lot of documents so I spend a lot of time searching for the same words. I basically have a list of about 50 words that I have to run through on each document to check to make sure they correspond to the correct document. The only way I can currently do this is by searching for each word individually...which takes forever. Any ideas or pointers would be appreciated.
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,246 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
04-Oct-2011, 05:50 AM #2
Hi, welcome to the forum,

I helped edit some macro code which searched for specific characters in all the text
http://forums.techguy.org/software-d...-2010-may.html

You will have to edit the macro to look for oil or whatever,
A table is created at the end with some information about where the text is located.

Maybe some additional editting will work for you.
Take a look and if you need help I'll see if I can figure out more.

I have attached the word doc for you to test.
Just run the macro
Attached Files
File Type: zip nashoomoo-Doc1.zip (22.5 KB, 17 views)
technical_editor's Avatar
technical_editor technical_editor is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Sep 2011
Experience: Advanced
04-Oct-2011, 09:21 AM #3
Re:
I don't think this code does what I want it to. Based on what I see from the code, it only counts characters, which doesn't really accomplish the problem of searching for multiple words at once.
technical_editor's Avatar
technical_editor technical_editor is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Sep 2011
Experience: Advanced
04-Oct-2011, 10:11 AM #4
This seems to work more or less
The code below will do pretty much what I want by finding each occurrence in the document of the words in the array and then displaying a message when each individual occurrence is found. Does anyone know how to do something a little more useful like creating a selectable list box or counting the number of occurrences of each item and displaying the count?

Sub search_fruit()
'
' search_fruit Macro
'
'
Dim vFindText
Dim r As Range
Dim i As Long
vFindText = Array("Apple", "Banana", "Orange", "Pear", "Plum")
For i = 0 To UBound(vFindText)
Set r = ActiveDocument.Range
With r.Find
.Text = vFindText(i)
Do While .Execute(Forward:=True) = True
r.Select
MsgBox r
Loop
End With
Next
End Sub
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
macro, ms word, word

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑