【问题标题】:ReadyState Complete stuck on ReadyState = 3ReadyState Complete 停留在 ReadyState = 3
【发布时间】:2020-02-13 21:39:12
【问题描述】:

在过去的几天里,我一直在运行这段代码来导航到这个城市数据网页,它一直运行良好,但突然之间,我在readyState = 4 周围出现了这个无限循环,奇怪的是有时有效,有时无效。

这是我的代码:

Dim IE as Object
Dim pageaddress as string
Dim city as string
Dim state as string

city = "Chicago"
state = "Illinois"

Set IE = CreateObject("internetExplorer.Application")
IE.Visible = True
pageaddress = "http://www.city-data.com/housing/houses-" & city & "-" & state & ".html"
IE.navigate (pageaddress)
Do
    DoEvents
Loop Until IE.readyState = 4

【问题讨论】:

标签: excel vba


【解决方案1】:

很遗憾,这是网页本身的问题,而不是您的代码。这意味着您将不得不添加一个计时器并在分配的时间之后刷新页面。

我会记下该页面的平均加载时间,并选择一个远高于该平均值的合理时间。

在本例中,我们将使用 10 秒。

Dim IE As Object
Dim pageaddress As String
Dim city As String
Dim state As String
Dim maxLoadingTime As Single, myTimer As Single

city = "Chicago"
state = "Illinois"

Set IE = CreateObject("internetExplorer.Application")
IE.Visible = True
pageaddress = "http://www.city-data.com/housing/houses-" & city & "-" & state & ".html"
IE.navigate (pageaddress)

'Set the max time to load
maxLoadingTime = 10     '< -- # of seconds to allow page to load -- <
myTimer = Timer

Do
    DoEvents
    If Timer >= maxLoadingTime + myTimer Then
        Debug.Print Time & " Notice: Connection Error. Refreshing webpage"
        IE.stop
        IE.Refresh
    End If
Loop Until IE.readyState = 4

【讨论】:

    【解决方案2】:

    我使用: For t = 1 To 1000: If objIE.readyState 4 or objIE.Busy Then t = 1: DoEvents: Next t 确保 readyState 或 busy 不要改变。

    【讨论】:

      猜你喜欢
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多