getHTTP with (excel) VBA?

2019-03-21 00:38发布

问题:

I'm searching for a query for an excel VBA macro to get a webpage html code as string. I've found some source with getHTTPrequest but I can't register .net framwork system.dll or link it.

any greenhorn friendly snippet out there? ;-) Thanks!

回答1:

Close enough: How can I send an HTTP POST request to a server from Excel using VBA? — It's even for Excel ;-)

Just use a GET request instead:

objHTTP.Open "GET", URL, False

MSDN: Using the WinHttpRequest COM Object - Retrieving Data Using Visual Basic



回答2:

Here's a compact function that returns the source of almost any specified URL, including HTTP and JSON.

(No references required.)

Public Function getHTTP(ByVal url As String) As String
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", url, False: .Send
        getHTTP = StrConv(.responseBody, vbUnicode)
    End With
End Function