2

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

2
  • Do you mean URL decoding into a String? e.g. java.net.URLDecoder.decode(url, "UTF-8"); Commented Dec 31, 2012 at 15:20
  • I need to read the HTML code, it is a football table and i decode it later. How can i save the HTML of the website ? In Java i can create a URL and then openconnection etc. etc. Commented Dec 31, 2012 at 15:23

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks - how do you avoid the response text being truncated?
I used your code and I get "Access denied" error at .Send. Any idea why? (Note: I used very common URLs (google.com, youtube.com, etc. that normally have no problem to be opened programmatically.)
Thanks. I found a solution using CreateObject("MSXML2.ServerXMLHTTP.6.0")
0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.