Question

Does anyone have a way that I can use a web query (or another automated VBA way) to import the full html code of a page into an excel page?

I need just about everything from <body> to </body> but don't mind if there is a solution that requires the full page import. I have had a good look online but can't come up with anything.

Was it helpful?

Solution

Here's 1 way to do it inside a VBA Macro. The htmlText object will contain all the HTML at the end of this sub.

Put a breakpoint before the End Sub, then add the htmlText object to Watch Window and you can then see all the data coming back in the Watch Window and decide how you want to extract the html data and where you want to put it in the Excel sheet etc.

Private Sub GetWebsiteHtml_Click()

    Dim x As Long, y As Long
    Dim htmlText As Object

    Set htmlText = CreateObject("htmlFile")

    With CreateObject("msxml2.xmlhttp")
        .Open "GET", "http://google.com", False
        .send
        htmlText.body.innerHTML = .responsetext
    End With

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top