在excel vba中获取html“id”标签

我正在研究一个UPS跟踪macros,我基本上使用的代码: UPS自动跟踪点击一个button 。

但是,我似乎无法提取我的操作代码后,我的喜好装运的状态。 以下是我所拥有的和我目前遇到的错误。

运行时错误“91”:对象variables或块variables未设置

码:

Sub test() ' open IE, navigate to the website of interest and loop until fully loaded Set ie = CreateObject("InternetExplorer.Application") my_url = "http://wwwapps.ups.com/WebTracking/track?loc=en_US" With ie .Visible = False .navigate my_url .Top = 50 .Left = 530 .Height = 400 .Width = 400 Do Until Not ie.Busy And ie.readyState = 4 DoEvents Loop End With ' Enter a value in the "Number" text box ie.document.getElementById("trackNums").Value = "1Z12345E1512345676" ' Click the "Submit" button Set Results = ie.document.getElementsByTagName("input") For Each itm In Results If InStr(1, itm.outerhtml, "Track", vbTextCompare) > 0 Then itm.Click Exit For End If Next ' Click the "Shipment Progress" button Set Results = ie.document.getElementsByTagName("input") For Each itm In Results If InStr(1, itm.outerhtml, "Shipment Progress", vbTextCompare) > 0 Then itm.Click Exit For End If Next ' Get the text from the "Shipment Progress Table" and assign to a variable Dim status As String Set doc = ie.document Do While ie.Busy Or ie.readyState <> 4 DoEvents Loop 'tbltxt = doc.getElementsByTagName("pkgstep1").innerText status = doc.getElementById("tt_spStatus").innerText ' process the text as desired ActiveCell.Value = status End Sub 

我遇到问题的确切路线是:

 status = doc.getElementById("tt_spStatus").innerText 

以下是我想从标签中拉取的text的截图。 标签

上面几行错误,你有这条线:

 Do Until ie.readyState = 4 

将其更改为:

 Do While ie.Busy Or ie.readyState <> 4