Search a range of words in each sections of a word document.

J

Joey

In my word document, there is a no. of section and each
section contain the following content <FaxNo:21123455>,
how can I search each section of the word document and
retrieve the <FaxNo:23333332> from the document??
 
C

Cindy M -WordMVP-

Hi Joey,
In my word document, there is a no. of section and each
section contain the following content <FaxNo:21123455>,
how can I search each section of the word document and
retrieve the <FaxNo:23333332> from the document??
Word's FIND functionality can be applied to the Selection
or the Range object. In order to search each section range,
the code would basically look like this:

Dim doc as Word.Document
Dim sec as Word.Section
Dim rng as Word.Range

Set doc = Documents.Open(szDocPath)

For Each sec in doc.Sections
Set rng = sec.Range
With rng.Find
'Find stuff here
End With
Next sec

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
G

Guest

-----Original Message-----
Hi Joey,

Word's FIND functionality can be applied to the Selection
or the Range object. In order to search each section range,
the code would basically look like this:

Dim doc as Word.Document
Dim sec as Word.Section
Dim rng as Word.Range

Set doc = Documents.Open(szDocPath)

For Each sec in doc.Sections
Set rng = sec.Range
With rng.Find
'Find stuff here
End With
Next sec

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e- mail
:)

.

For Each sec in doc.Sections
Set rng = sec.Range
With rng.Find
'Find stuff here
End With
Next sec

About the 'Find stuff here, how to write the code if I
want to found "<To:xxxxxx xxxx>" in the document??
 
C

Cindy M -WordMVP-

For Each sec in doc.Sections
Set rng = sec.Range
With rng.Find
'Find stuff here
End With
Next sec

About the 'Find stuff here, how to write the code if I
want to found "<To:xxxxxx xxxx>" in the document??
Best is to start out in the Word interface and test until
you've discovered the "Find" syntax that works to do what
you want. Be sure to click the <<MORE>> button in the
dialog box so that you can access all the tools Word
provides, especially wildcards and the special codes
button. More information on the codes can be found in
Word's Help, and there should be some useful information on
using Find and automating Find over VBA on the
mvps.org/word website.

Once you've found the "Find" syntax you need, record using
it in a macro to get the basic code you can then transfer
into your project.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top