I'm working in Excel to extract content of a table from a web page and populate Excel sheet cells with it. I'm trying to extract data from a table that gets loaded to a web page after show results method gets called. I have an error that says "Run-time error '424' Object required".
Sub extractDataFromTable()
Dim IE As Object
Dim theTable As Object
Dim form As Variant, button As Variant
Dim doc As Object
Set IE = CreateObject("InternetExplorer.Application")
' navigate to a web page
With IE
.Visible = True
.navigate ("http://www.sizemyups.com")
End With
While IE.ReadyState <> 4
DoEvents
Wend
Set doc = IE.document
' prefill the data to the website
doc.getElementsByName("load").Item.innertext = 50
doc.getElementsByName("line").Item(0).Value = "Endeavor Series"
' make the table with data load
Set form = doc.getElementsByName("line")
Set button = form(0).onchange
form(0).onchange
' set the data from the first tr tag
Set theTable = doc.getElementById("mytable").getElementsByTagName("tr")
' extract the data from tag and assign it to the first cell in the sheet
Dim myValue As String
myValue = theTable(0).innertext
Cells(1, 1).Value = "Cell content " & myValue
End Sub
If I change the Set theTable = doc.getElementById("mytable").getElementsByTagName("tr")
to Set theTable = doc.getElementById("homepu").getElementsByTagName("tr")
, I don't get any errors, and the code works as I want it. I've been trying to figure out what's wrong, but didn't get anywhere. What am I doing wrong?