0

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

6 Comments

The GetIE function is working properly, the error was thrown when i have added the wait function
@AdamVoga Agreed. I just tested your code in Excel and located the problem. See my updated answer above.
why do the brackets make a difference? Is it something to do with 'making a copy'?
@AdamVoga Just updated answer with explanation so others can also benefit from it.
+1, for even more about this, read this DDOE post,
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.