Alpan67
Alpan67

Reputation: 105

Reading HTML file in VBA Excel

i want to read the HTML code in VBA (something like URL in Java). I need to save it in a string. I parse it afterwards.

alpan67

Upvotes: 2

Views: 28811

Answers (2)

Daniel
Daniel

Reputation: 13122

Here's a function for you. It will return the String of the HTML returned by a given URL.

Function GetHTML(URL As String) As String
    Dim HTML As String
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", URL, False
        .Send
        GetHTML = .ResponseText
    End With
End Function

Just make sure your provided URL is well formed. I.E. it includes the http:// or https:// if appropriate.

For Example: GetHtml("www.google.com") is incorrect.
You would want GetHtml("https://www.google.com/")

Upvotes: 10

bonCodigo
bonCodigo

Reputation: 14361

Upvotes: 0

Related Questions