我正在研究UPS跟踪宏,我基本上使用了以下代码:UPS Automated tracking clicking a button。
但是,在我根据自己的喜好操作代码之后,我似乎无法提取货件的状态。以下是我所拥有的以及我目前遇到的错误。
运行时错误'91': 对象变量或未设置块变量
代码:
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