I have the following code:
I'm seeing an error message that says: Run time error 424: Object required.
on this line: For Each ele In objIE.document.getElementById("mdcTable").getElementsByTagName("tr")
Do I have the wrong .getElementById? Thanks!
Code:
Sub RetrieveData()
'dimension (set aside memory for) our variables
Dim objIE As InternetExplorer
Dim ele As Object
Dim y As Integer
'start a new browser instance
Set objIE = New InternetExplorer
'make browser visible
objIE.Visible = True
'navigate to page with needed data
objIE.navigate "http://www.wsj.com/mdc/public/page/2_3020-treasury.html"
'wait for page to load
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
'we will output data to excel, starting on row 1
y = 1
'look at all the 'tr' elements in the table,
'and evaluate each, one at a time, using 'ele' variable
For Each ele In objIE.document.getElementById("mdcTable").getElementsByTagName("tr")
'show the text content of 'tr' element being looked at
Debug.Print ele.textContent
'each 'tr' (table row) element contains 4 children ('td') elements
'put text of 1st 'td' in col A
Sheets("Data").Range("A" & y).Value = ele.Children(0).textContent
'put text of 2nd 'td' in col B
Sheets("Data").Range("B" & y).Value = ele.Children(1).textContent
'put text of 3rd 'td' in col C
Sheets("Data").Range("C" & y).Value = ele.Children(2).textContent
'put text of 4th 'td' in col D
Sheets("Data").Range("D" & y).Value = ele.Children(3).textContent
'increment row counter by 1
y = y + 1
'repeat until last ele has been evaluated
Next
End Sub
I'm seeing an error message that says: Run time error 424: Object required.
on this line: For Each ele In objIE.document.getElementById("mdcTable").getElementsByTagName("tr")
Do I have the wrong .getElementById? Thanks!