Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Word 2007 Macro - Find text in document

Posted on 2007-04-03
2
Medium Priority
?
1,686 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

618 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