Find function problems

N

netloss

I am having trouble with the .find function in MSWord. The following
code snippet is run from a user form button click event.

If the built-in Find Box is open when the button is clicked, the code
fails (that is, fails to find an occurence of 'styleX' that DOES exist)
and the msgbox "Error" is displayed. If the built-in Find box is
closed, the code works.

If The find Box is open and I click the button on the userform twice,
it fails the first time (but doesn't crash because the error is
trapped) and works the second time. However, when going back to the
document text, the arrow keys and all shortcut keys are disabled until
the document is closed and reopened.

Is there a way to get this to work with the find box left open? Or,
less elegantly, is there a way in VBA to close the find box and reopen
it after the code runs? And why does any of this disable the arrow and
shortcut keys?

Thanks for any advice.
================================

Dim rSearch As Range
Set rSearch = docSource.Range

With rSearch.Find
.ClearFormatting
.Text = ""
.Style = "StyleX"
.Execute

If .Found = True Then
Set rTemp = rSearch.Duplicate
GoTo NextPart
Else
MsgBox "Error."
Exit Sub
End If
End With

NextPart:
 

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