Finding text inside a document

M

mlsrinivas

Hi,

I am trying to process a set of documents and return the list of
documents with the text '_____' (five underscores).

Initially, I thought it was easy, but it is not the case. I tried using

I method:
Application.ActiveDocument.Select
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = True
.Wrap = wdFindContinue
.Execute FindText:="_____"
End With

II method:
b = Selection.Find.Execute("_____", True, True, , , , True,
wdFindContinue)

In both the cases, 'MatchWholeWord' is not working. Even if there are
more than 5 underscores it is select.

Any clues, how to do this?

Thanks

Srinivas
 
H

Helmut Weber

Hi Srinivas

like this and in many other ways:

Sub Macro123x()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "_____"
While .Execute
If rDcm.Characters.First.Previous <> "_" _
And _
rDcm.Characters.Last.Next <> "_" Then
rDcm.Select ' for testing
End If
Wend
End With
End Sub

Note:
Depending on what you do with the found range,
you may to define the range to be searched anew.
And
if "_____" are the first five characters
of a doc, then this case would need special treatment.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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