Solved

Word 2007 Macro - Find text in document

Posted on 2007-04-03
2
1,674 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

777 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