我有以下excel vba代码,可以访问OFAC网站,执行查询,然后将结果返回到excel工作表。该代码过去运行良好。但是今天,一个新用户尝试使用此代码,并收到以下错误:
WebBrowserii的方法繁忙失败。
有问题的代码如下:While ie.Busy
。
有人知道问题的原因,更重要的是如何解决它?
Sub GetOFAC()
Dim strResults As String
Dim ofacname As String
ofacname = Excel.Range("Company").Value
Application.ScreenUpdating = False
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://sanctionssearch.ofac.treas.gov/"
ie.Fullscreen = True
Application.StatusBar = "Submitting"
' Wait while IE loading...
While ie.Busy
DoEvents
Wend
' **********************************************************************
delay 1
ie.Document.getElementById("ctl00_MainContent_txtLastName").Value = ofacname
delay 1
ie.Document.getElementById("ctl00_MainContent_btnSearch").Click
Application.SendKeys "(%{1068})"
'**********************************************************************
Application.StatusBar = "Form Submitted"
'Wait while the results load
Application.Wait (Now + TimeValue("0:00:02"))
'The results have loaded so select the table and get the text
strResults = ie.Document.getElementById("scrollResults").InnerText
'MsgBox strResults
ie.Quit
Set ie = Nothing
'The results have loaded so select the table and get the text
Application.Goto Reference:="ofac_drop"
ActiveCell.Value = Trim(LTrim(RTrim(strResults)))
Application.Goto Reference:="OFCA_LANDING"
ActiveSheet.Paste
Application.Goto Reference:="start"
End Sub