货件跟踪,返回date给出运行时间错误424对象必需

所以我正在为一个同事做一个项目,我遇到了一个问题。 我以前从来没有使用过Excel VBA,而且在编码方面我几乎没有什么培训。 StackOverflow和其他几十个网站已经得到了巨大的帮助。 我只是不知道该去哪里。

目标。

  • 导航到网页
  • 等待页面加载
  • 将交货date返回到Excel(单元格b1)

这是我的代码到目前为止

Public Function RoadRunnerTracking() Dim IE1 As Object Dim DeliveryCollection As Object Dim ProUrl As String Set IE1 = CreateObject("InternetExplorer.application") ProUrl = "https://www.rrts.com/Tools/Tracking/Pages/MultipleResults.aspx?PROS=" & Range("a1") With IE1 .Visible = True .Navigate ProUrl Do Until Not IE1.Busy And IE1.readyState = 4: DoEvents: Loop End With Set DeliveryCollection = Trim(IE1.document.getElementsByTagName("Span")(16).innerText) 'THIS LINE RETURNS A RUN TIME ERROR 424 OBJECT REQUIRED Range("b1").Value = DeliveryCollection Set IE1 = Nothing End Function 

这不是一个抛光的function,但我知道。 我只是想解决一些问题。

我不明白的是,我testing了另一个function的行,它工作正常。 我欺骗了testing函数直接粘贴链接到结果页面,而不是运行跟踪号码,但我会认为这将是相同的。

这里是该行似乎工作的代码。

 Public Function PartTwoTest() Dim IE1 As Object Set IE1 = CreateObject("InternetExplorer.application") With IE1 .Visible = True .Navigate "https://www.rrts.com/Tools/Tracking/Pages/MultipleResults.aspx?PROS=359607744" Do Until IE1.readyState = 4 DoEvents Loop End With DeliveryCollection = Trim(IE1.document.getElementsByTagName("Span") (16).innerText) Range("b1").Value = DeliveryCollection Set IE1 = Nothing End Function 

任何帮助,将不胜感激。

我认为deliverycollection需要是一个string。