Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ie.busy not working well [VBA]

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

like image 406
Black Dagger Avatar asked Oct 12 '13 13:10

Black Dagger


1 Answers

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.

like image 192
jacouh Avatar answered Oct 25 '22 09:10

jacouh