VBA hanging on ie.busy and readystate check

后端 未结 3 1782
时光取名叫无心
时光取名叫无心 2020-12-01 15:04

I am trying to grab some football player data from a website to fill a privately used database. I\'ve included the entire code below. This first section is a looper that cal

3条回答
  •  既然无缘
    2020-12-01 15:55

    I've found this post very helpful when I encountered similiar problem. Here is my solution:

    I used

    Dim browser As SHDocVw.InternetExplorer
    Set browser = New SHDocVw.InternetExplorer
    

    and

    cTime = Now + TimeValue("00:01:00")
    Do Until (browser.readyState = 4 And Not browser.Busy)
        If Now < cTime Then
            DoEvents
        Else
            browser.Quit
            Set browser = Nothing
            MsgBox "Error"
            Exit Sub
        End If
    Loop
    

    Sometimes page is loaded but code stops on DoEvents and goes on and on and on. Using this code it goes on only for 1 minute and if browser is not ready it quits the browser and exits sub.

提交回复
热议问题