Solved

Word 2007 Macro - Find text in document

Posted on 2007-04-03
2
1,681 Views
Last Modified: 2007-11-27
I have some text that I want to find all instances of in my document, what is the synatx of the code?  I attempted to discover it in a macro, but it uses the execute to determine the number and I cant seem to get any further, please help!
0
Comment
Question by:jessnjeff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 7

Expert Comment

by:gbahri
ID: 18848436
Hi  jessnjeff,

You can use "Do while .... loop" to achieve this, here is a snippet for the same. Let's say, you wish to find "jessnjeff":

========================================================================

Sub FindAllInstances()

Selection.HomeKey Unit:=wdStory
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindStop ' find till eof
    .MatchWildcards = False
    .Text = "jessnjeff"
    Do While .Execute = True
          MsgBox Selection.Text ' Will show text found in document (instances of jessnjeff one by one.)
    Loop
       
   End With
End Sub

========================================================================

Hope, this serves your purpose,

thanks,

GBahri


0
 
LVL 7

Accepted Solution

by:
gbahri earned 125 total points
ID: 18972045
Any update?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question