ie.busy 工作不正常 [VBA]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19334880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:53:22  来源:igfitidea点击:

ie.busy not working well [VBA]

internet-explorervba

提问by Black Dagger

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.

在我的代码中添加暂停,同时 Internet Explorer 刷新。但这似乎并不奏效。'某些代码部分过早执行并引发错误。

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

请建议一个可靠的替代 ie.busy

回答by jacouh

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

在我们的代码中,ie.Busy(InternetExplorer.Application Object)并不是很可信。这是我们使用和工作的内容:

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.

你可以试试。