Use of Find object

M

m92410

Hi

I have code in a VB6 application like this:

Dim oFind As Find
Set oFind = .Tables(1).Rows(1)Range.Find
With oFind
.Forward = True
.Text = "CR"
.Replacement.Text = "^p"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

The code inside the With statement would not execute until
I changed the data type for oFind to type Object, like
this:

Dim oFind As Object

My question: Why wouldn't this work with oFind declared as
type "Find"?

Thanks
 
M

martinique

It might be that the various references in your app include more than one
'Find' object. (Don't know off-hand what it might be, but eg both Word and
Excel have Range objects.) In the absence of an explicit declaration, VB
will use the first Find object it encounters in any referenced library.

Try declaring the object type explicitly:

Dim oFind as Word.Find

This is good practice anyway, for all object declarations.
 

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