5

I am using :

While ie.busy
DoEvents
Wend

' Some Code

To add a pause in my code, while internet explorer refreshes. But this doesnt seem to be working well. The 'Some code part is getting executed pre-maturely and throwing an error.

I have tried using other methods as well. for e.g.

Errorhandler:

While ie.busy
DoEvents
Wend

On Error Goto Errorhandler
'Some Code

But even this isnt working and sometimes the code is esecuted pre maturely.

Please suggest an infallible alternative to ie.busy

Black Dagger
  • 377
  • 2
  • 6
  • 18
  • 2
    See [this link](http://stackoverflow.com/a/19019200/1768303) for how to handle a busy waiting loop. You should not be checking only against `.busy`, but also against `ReadyState = 4 'Complete`. – David Zemens Oct 13 '13 at 23:44

1 Answers1

5

In our code, ie.Busy (InternetExplorer.Application Object) is not very credible. Here is what we use and works:

Enum READYSTATE
    READYSTATE_UNINITIALIZED = 0
    READYSTATE_LOADING = 1
    READYSTATE_LOADED = 2
    READYSTATE_INTERACTIVE = 3
    READYSTATE_COMPLETE = 4
End Enum

Dim strUrl
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
'....
' do navigation...
'
strUrl = "http://www.example.com/"
ie.Navigate strUrl

'
' waiting for the ie complete loading:
'
Do While (ie.Busy Or ie.READYSTATE <> READYSTATE.READYSTATE_COMPLETE)
  DoEvents
Loop

'
' here below you do stuffs on the new loaded URL:
'

You can try.

jacouh
  • 8,473
  • 5
  • 32
  • 43