Html 表格中每行的VBA excel将电子表格中的单元格与网页表格中的单元格匹配

Html 表格中每行的VBA excel将电子表格中的单元格与网页表格中的单元格匹配,html,vba,excel,Html,Vba,Excel,这是一种重新发布,以重新组织我的问题,但是: 我正在尝试将我的电子表格B1单元格文本与网页表格第10列中的所有单元格进行匹配。如果有匹配项,我想复制第4单元格文本中的行。到目前为止,我已经: Dim colRows As Object Dim objDataGrid As Object Dim xobj1 As Object Dim xcel As Object Set objDataGrid = IE.Document.getElementById("DataGridReservations

这是一种重新发布,以重新组织我的问题,但是:

我正在尝试将我的电子表格B1单元格文本与网页表格第10列中的所有单元格进行匹配。如果有匹配项,我想复制第4单元格文本中的行。到目前为止,我已经:

Dim colRows As Object
Dim objDataGrid As Object
Dim xobj1 As Object
Dim xcel As Object

Set objDataGrid = IE.Document.getElementById("DataGridReservations")
Set colRows = objDataGrid.getElementsByTagName("tr")

For Each element In colRows
    Set xcel = colRows.getElementsByTagName("td")
        If Range("B1").Text = xcel.Item(9).innertext Then
        Range("H" & (ActiveCell.Row)) = xcel.Item(3).innertext
        Else
        Range("H" & (ActiveCell.Row)) = "0"
        End If
Exit For

Next
我在线路上出错了

set xcel = colRows.getElementsByTagName....

把我的头发拔出来。另外,为了确保“For Each element in colRows”元素只会引用我在set colRows中定义的“getElementsbyTagName(“tr”)”。它也不会拾取tr中括号内的td标签,对吗?

我们可以有更多的成功机会:

Sub sof20255214WebpageCell()

  Dim colRows As Object
  Dim objDataGrid As Object
  Dim xobj1 As Object
  Dim element
  Dim xcel As Object

  Dim IE

  Set IE = CreateObject("InternetExplorer.Application")
  IE.navigate "http://www.example.com/DataGridPage.php"

  While (IE.Busy Or IE.READYSTATE <> 4)
    DoEvents
  Wend

  Set objDataGrid = IE.Document.getElementById("DataGridReservations")
  Set colRows = objDataGrid.getElementsByTagName("tr")

  For Each element In colRows
    Set xcel = element.getElementsByTagName("td")
    If Range("B1").Text = xcel.Item(9).innerText Then
      Range("H" & (ActiveCell.Row)) = xcel.Item(3).innerText
    Else
      Range("H" & (ActiveCell.Row)) = "0"
    End If
    Exit For
  Next

  IE.Quit

End Sub
因为colRows是行的集合,但不是单行对象。不过,您可以使用以下(好):


错误消息是什么?对象不支持此方法或属性
Set xcel=element.getElementsByTagName(“td”)
Object变量未在行上设置错误,如果范围(“B1”)…运行它引用一行,我必须将其写入范围(“B1”)。文本,否则它将无法读取单元格内容。。。我假设,因为单元格的格式是常规的,而不是数字。只是试着去做,但还是失败了。
Set xcel = colRows.getElementsByTagName("td")
Set xcel = colRows.Item(0).getElementsByTagName("td")