Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading HTML file in VBA Excel

Tags:

vba

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

like image 247
Alpan67 Avatar asked Dec 08 '25 22:12

Alpan67


1 Answers

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/")

like image 138
Daniel Avatar answered Dec 13 '25 20:12

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!