ie.busy运作不佳[VBA]

Bla*_*ger 5 internet-explorer vba

我在用 :

While ie.busy
DoEvents
Wend

' Some Code
Run Code Online (Sandbox Code Playgroud)

在我的代码中添加暂停,同时Internet Explorer刷新.但这似乎并没有奏效.'某些代码部分正在成熟地执行并抛出错误.

我也尝试过使用其他方法.例如

Errorhandler:

While ie.busy
DoEvents
Wend

On Error Goto Errorhandler
'Some Code
Run Code Online (Sandbox Code Playgroud)

但即使这样也不行,有时代码会在成熟之前被执行.

请建议ie.busy的绝对替代方案

jac*_*ouh 5

在我们的代码中,ie.Busy(InternetExplorer.Application对象)不是很可靠。这是我们使用和工作的方式:

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:
'
Run Code Online (Sandbox Code Playgroud)

你可以试试。