Selection.Find reached end of file condition

R

robk

Hi
I'm trying to search the document for special word with all what after until
paragraph ends.
If you try manualy for Edit->Find , FindNext, you get askDialog that you
reached the EOF
and if you're answer is no it stops for searching.

Is there that condition (don't know how to tell). Look in my code:


For i = 0 To 100
Selection.Find.ClearFormatting
With Selection.Find
.Text = "PIL:*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
If i > 0 Then
Selection.Find.Execute
End If
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
pil = pil + Selection.Text

' if it reached the end of file exit for

Next i
 
S

Steven Marzuola

robk said:
Hi
I'm trying to search the document for special word with all what after until
paragraph ends.
If you try manualy for Edit->Find , FindNext, you get askDialog that you
reached the EOF
and if you're answer is no it stops for searching.

Is there that condition (don't know how to tell). Look in my code:


For i = 0 To 100
Selection.Find.ClearFormatting
With Selection.Find
.Text = "PIL:*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
If i > 0 Then
Selection.Find.Execute
End If
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
pil = pil + Selection.Text

' if it reached the end of file exit for

Next i

Maybe this will help ...

When VB runs the Selection.Find.Execute command, it sets the .Found
variable to TRUE or FALSE, depending on whether the Find was successful.
You can use it to control what your program next. I use it often,
here's an example. This would stop after it finds the last \ character
in my document.

With Selection.Find
.ClearFormatting
.Text = "\": .Replacement.Text = "":
.Execute
If Not .Found Then Exit Sub
End With

Steven
 
H

Helmut Weber

Hi,

Sub Test4444()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
ResetSearch
With rTmp.Find
.Text = "PIL:*^013"
.MatchWildcards = True
While .Execute ' = if found
rTmp.Select ' for testing
' pil = pil + Selection.Text ???
' means pil gets longer and longer ???
Wend
End With
ResetSearch
End Sub
' ---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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