Reputation: 124
I'm trying to create a function called wait that would use an object:
Function wait(browser As Object)
' loop until the page finishes loading
Do While browser.READYSTATE <> 4
Loop
End Function
I also have:
Function GetIE() As Object
On Error Resume Next
Set GetIE = CreateObject("InternetExplorer.Application")
End Function
and:
Dim appIE As Object
Set appIE = GetIE
sURL = "http://google.com"
wait (appIE)
But i'm getting "Run time error '424'; Object required. Any idea?
Upvotes: 0
Views: 350
Reputation: 20935
Change this line
wait (appIE)
to
wait appIE
Explanation: In VBA, whenever you call a Function that has parameters, if you are not doing anything with the return value, then you have to call it without the parenthesis. In this case, since the code is not returning anything, it should be defined as a Sub
and not a Function
. The same thing applies to Sub
routines that take parameters also, i.e. you have to call it without parenthesis with the parameters separated by comma.
Further Reading (via @doug) : Quick VBA Tip: Parentheses
Upvotes: 2