Waiting for Internet Explorer to finish loading a web page

C

cjakeman

I've had some trouble automating Internet Explorer from VBA (Excel XP).
I tried the usual code:

While oIE.Busy And oIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend

and found that .Busy = False and .ReadyState <> READYSTATE_COMPLETE
were identical so you don't need to check both.

However further trials showed the DOM may not be fully populated by the
time .Busy goes False. For example, you might analyse the DOM with code
like:

Set oAllATags = oIE.Document.getElementsByTagName("a")

which extracts a collection of all the <A> tags in the document. If you
repeat this code in a loop working with a large document, you will find
the size of the collection grows from zero. It may start to grow before
..Busy goes false or after .Busy goes False depending on the document.

I now have a WaitWhileBusy procedure that waits until the size of the
collection has been stable for more than 100msecs. My programs for
automating IE are now much more robust.

Has anyone else seen this and is there a more elegant way to get the
same result?
 

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