Searching to the End of the Document

D

D Collins

Hello,

I have a user form that locates certain words, like a
spellcheck dialog would do. It locates the word, then I
allow the user to edit it (by making the form modeless),
then the user presses a button to do the search again.

My question: Each time the user presses the search
button, it's activating the code again. Is there a way
to keep track of whether or not you have searched the
entire document for this word? I know that spellcheck
does this by telling you that you've reached the end.
I'm assuming that a loop would not accomplish this, as I
need for the user to interact with the first word it
finds in the search, hence I've made the form modeless
and I needed the rest of the code to stop for a moment.

Thanks, D.
 
H

Helmut Weber

Hi D,
this may look terrible to the alltime great experts,
but it certainly works here and now.
userform2 declarations
Dim iStr As Integer
Dim iEnd As Integer
Dim oRng As Range
---
Private Sub UserForm_Initialize()
Set oRng = Selection.Range
oRng.Start = 0
oRng.End = ActiveDocument.Range.End
End Sub

Sub test()
UserForm2.Show vbModeless = True
End Sub
---
Private Sub CommandButton1_Click()
With oRng.Find
.Text = "and"
If .Execute = False Then
MsgBox "done"
Unload Me
Exit Sub
End If
oRng.Select
iEnd = oRng.End
oRng.Start = iEnd
oRng.End = ActiveDocument.Range.End
End With
End Sub
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
H

Helmut Weber

iStr is useless
hw

Gruss
Helmut Weber
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

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