MSXML2.XmlHttp
This is on its way out
Reference - Microsoft XML v6.0
Adding this reference allows you to use the MSXML application programming interfaces from within VBA.
This is an XML parser which supports DOM that can be used in VBA to access and manipulate XML data.
It is possible to treat an XML file as a text file and parse it using traditional methods but is not very efficient.
However because the XML data is structured it is far easier to use an XML parser instead.
There are lots of different type of XML parsers but for the purposes of VBA you will want to use a parser that supports XML Document Object Model (DOM).
An XML parser that supports DOM will take the XML data and expose it via a set of objects that we can program against.
Dim xmlhttp As New MSXML2.XMLHTTP 'whatever version is installed, could be 5.0 or 4.0
Dim xmlhttp As New MSXML2.XMLHTTP60 'for Microsoft XML, v 6.0
Dim xmlhttp As New MSXML2.XMLHTTP.6.0 'for Microsoft XML, v 6.0
CreatObject("MSXML2.XMLHTTP")
CreatObject("MSXML2.XMLHTTP60")
CreatObject("MSXML2.XMLHTTP.6.0")
CreatObject("MSXML2.XMLHTTPRequest60") 'not recommended
Uses the browser HTTP stack (WinInet), which introduces quirks that can break JSON API calls.
You want the simplest possible GET request
You don't need advanced headers or authentication
Supports proxy and server credentials
Sub Request()
Dim xmlhttp As MSXML2.XMLHTTP
Dim sDownloadDate As String
Dim sResponse As String
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
sDownloadDate = VBA.Format(VBA.Now, "yyyy-mm-dd")
Call xmlhttp.Open("GET", modConstants.g_sURL_PREFIX & modConstants.g_sURL_SUFFIX_COMBINEDINFO & sDownloadDate, False)
xmlhttp.send
sResponse = xmlhttp.responseText
End Sub
GET
This enables you to download an internet file using the Microsoft XML object and is an alternative to using the URLDownloadToFile API.
Requires a reference to the Microsoft XML library
The responseBody method of the XMLHHTP object returns a byte array
Public Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As MSXML2.XMLHTTP
Dim i As Long,
Dim vFF As Long
Dim oResp() As Byte
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False
oXMLHTTP.Send
Do While (oXMLHTTP.readyState <> 4 )
DoEvents
Loop
oResp = oXMLHTTP.responseBody
vFF = FreeFile
If Dir(vLocalFile) <> "" Then
Kill vLocalFile
End If
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
Set oXMLHTTP = Nothing
End Function
Public Sub Testing()
Call SaveWebFile ("http://www.bettersolutions.com/websitelogo.png", "C:\websitelogo.png" )
ActiveSheet.Pictures.Insert "C:\websitelogo.png"
Kill "C:\C:\websitelogo.png"
End Sub
POST
Dim xmlhttp As MSXML2.XMLHTTP
Dim myurl As String
Set xmlhttp = CreateObject("MSXML2.XMLHTTP)
myurl = "http://requestb.in/15oxrjh1"
xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.Send "name=codingislove&email=admin@codingislove.com"
MsgBox (xmlhttp.responseText)
xmlhttp.setRequestHeader "Content-Type", "application/json"
'assumes the data returned is in a very basic key-value pair json format
'{"id":1,"title":"hello"}
POST
Dim SoapRequest As String
Dim Server As String
Dim Request As New MSXML2.XMLHTTP
Dim Response As String
Server = "http:///service/vestaService/"
SoapRequest = [A2].Value
With Request
.Open "POST", Server, False
.send SoapRequest
Response = .responseText
End With
Debug.Print Response
MsgBox Response
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext