?
Solved

Word 2007 Macro - Find text in document

Posted on 2007-04-03
2
Medium Priority
?
1,685 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 500 total points
ID: 18972045
Any update?
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
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…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses

770 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