VBA excel For each row in table match cell in spreadsheet with cell in webpage table

后端 未结 1 593
鱼传尺愫
鱼传尺愫 2021-01-25 21:45

This is kind of a repost to reorganize my question but:

I\'m trying to match my spreadsheets cell B1 text with all the cells in the 10th column of a table on a webpage.

相关标签:
1条回答
  • 2021-01-25 22:09

    We could have more chance for success with this:

    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
    

    Anyway, we cannot use this (BAD):

    Set xcel = colRows.getElementsByTagName("td")
    

    As colRows is a collection of rows, but not a single row object. Nevertheless, you can use this (Good):

    Set xcel = colRows.Item(0).getElementsByTagName("td")
    
    0 讨论(0)
提交回复
热议问题