1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

MS Word 2010 macro help

Discussion in 'Business Applications' started by technical_editor, Sep 29, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. technical_editor

    technical_editor Thread Starter

    Joined:
    Sep 29, 2011
    Messages:
    3
    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.
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    5,946
    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-development/1015177-help-vba-word-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:

  3. technical_editor

    technical_editor Thread Starter

    Joined:
    Sep 29, 2011
    Messages:
    3
    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.
     
  4. technical_editor

    technical_editor Thread Starter

    Joined:
    Sep 29, 2011
    Messages:
    3
    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
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1019906