J S said:
This code does not work and generates an error like "Object required"
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
WaitUntilReady (oIE)
Public Sub WaitUntilReady(oIE As Object)
End Sub
This code does work! Why do I need to declare the oIE variable as an
object? Should VB know that its an object after I Set it equal to
one???
Dim oIE as Object
Set oIE = CreateObject("InternetExplorer.Application")
WaitUntilReady (oIE)
Public Sub WaitUntilReady(oIE As Object)
End Sub
Begging your pardon, but that code you say "does work" does *not*
work -- not on my system, at least, and I wouldn't expect it to. Your
calling syntax is incorrect for passing the oIE variable. You must
either write
WaitUntilReady oIE
or
Call WaitUntilReady(oIE)
to pass the object variable to the subroutine. By wrapping it in
parentheses unnecessarily, you are telling VB to pass the *value* of the
object; and what is the value of an IE application? As best I can tell
it's the string value "Microsoft Internet Explorer". This does work:
Dim oIE As Object
Set oIE = CreateObject("InternetExplorer.Application")
WaitUntilReady oIE
On the other hand, suppose you correct that error and still leave off
the "As Object", so you have
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
WaitUntilReady oIE
The above doesn't compile, giving you "ByRef argument type mismatch".
That's because, by not specifying the type when you declare oIE, you are
declaring it as a Variant. WaitUntilReady wants an Object, not a
Variant -- not even a Variant that points to an Object, apparently.
Rudimentary tests suggest that if you declare WaitUntilReady to accept
its argument passed by value, not by reference ...
Public Sub WaitUntilReady(ByVal oIE As Object)
.... then it will work even with oIE as a Variant, so long as it points
to a suitable object. But there's no good reason for doing that, since
simply declaring oIE As Object, not as Variant, resolves the matter.