VBA to scrape Web scroll-table into excel

bezuchoff

New Member
Joined
May 31, 2018
Messages
3
Hello,

I have been trying putting together a code to get scroll table data from web to excel from an internal url which does not open in IE. The code I have, however, only takes table (column) headings, not the values from table itself. The table on web updates every once a while on would be great get it into excel. I have table ID, table data (cells) contain links as well as dynamic values.

Any help would be highly appreciated. Thanks a lot.


Sub ScpareWebTable()

Dim xml As Object
Dim html As MSHTML.IHTMLDocument
Dim objTable As Object
Dim result As String
Dim trow As Object
Dim tcel As Object


Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
With xml
.Open "GET", "https://company_xx.internal.co.uk/station/linehaul", False
.send
End With


result = xml.responseText
Set html = CreateObject("htmlfile")


html.body.innerHTML = result


Set objTable = html.getElementsByTagName("table")


Set trow = html.getElementsByTagName("tr")
Set tcel = html.getElementsByTagName("td")

For Each tcel In trow
Debug.Print tcel.innerText
Next tcel

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
One important comment - when I call the table by its ID Set objTable = html.getElementsById("linehaulDataTable") I am getting Run-time error 438 (Object doesn't support this property or method).
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top