HTTP Requests in Excel VBA: GET and POST Examples (2026)

How do I make an HTTP request in Excel VBA? Create an MSXML2.ServerXMLHTTP60 object (or WinHttp.WinHttpRequest.5.1), call Open with the method and URL, set any headers, call Send, then read Status and ResponseText. The GET and POST macros below send JSON headers and check the status code, so you can paste them into a module and change the URL.
Note (November 2026): I updated the examples to current endpoints and added error handling. I could not run Excel while writing this update, so I checked the calls against Microsoft’s documentation for ServerXMLHTTP and WinHttpRequest. If a macro fails on your machine, tell us in the comments.
Excel is a powerful and most popular tool for data analysis! HTTP requests in VBA gives additional capabilities to Excel. XmlHttpRequest object is used to make HTTP requests in VBA. HTTP requests can be used to interact with a web service, API or even websites. Let’s understand how it works.

Open an excel file and open VBA editor (Alt + f11) > new module and start writing code in a sub
Public sub XmlHttpTutorial
End Sub
Define XMLHttpRequest
Define http client using following code
Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
If you need VBA’s Intellisense autocomplete then do it this way :
First, Add a reference to MSXML (Tools > references)
Select appropriate version based on your PC : 1. Microsoft XML, v 3.0. 2. Microsoft XML, v 4.0 (if you have installed MSXML 4.0 separately). 3. Microsoft XML, v 5.0 (if you have installed Office 2003 - 2007 which provides MSXML 5.0 for Microsoft Office Applications). 4. Microsoft XML, v 6.0 for latest versions of MS Office.
Then define http client
Dim xmlhttp As New MSXML2.XMLHTTP
'Dim xmlhttp As New MSXML2.XMLHTTP60 for Microsoft XML, v 6.0
VBA Intellisense will show you the right one when you start typing.
Make requests
Requests can be made using open and send methods. Open method syntax is as follows :
xmlhttp.Open Method, URL, async(true or false)
I’m using httpbin.org to test requests. It echoes back whatever you send, so you can see exactly what your macro posted.
A simple GET request would be :
Public Sub SimpleGet()
Dim http As Object
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "GET", "https://httpbin.org/get", False
http.Send
MsgBox http.ResponseText
End Sub
Run this code, a message box is displayed with the response of the request.
GET request with JSON headers and error handling
Real APIs can time out, return an error status or be unreachable. This version asks for JSON, sets timeouts, traps errors and checks the HTTP status before using the response:
Public Sub GetJson()
Dim http As Object
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
On Error GoTo Failed
http.Open "GET", "https://httpbin.org/get", False
http.setTimeouts 5000, 5000, 10000, 10000 'resolve, connect, send, receive (ms)
http.setRequestHeader "Accept", "application/json"
http.Send
If http.Status = 200 Then
Debug.Print http.ResponseText 'parse it with VBA-JSON, see the link below
Else
MsgBox "Request failed: " & http.Status & " " & http.statusText
End If
Exit Sub
Failed:
MsgBox "Could not reach the server: " & Err.Description
End Sub
POST request with a JSON body
To send JSON, set the Content-Type header to application/json and pass the JSON text to Send:
Public Sub PostJson()
Dim http As Object, payload As String
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
payload = "{""name"": ""codingislove"", ""topic"": ""vba""}"
On Error GoTo Failed
http.Open "POST", "https://httpbin.org/post", False
http.setTimeouts 5000, 5000, 10000, 10000
http.setRequestHeader "Content-Type", "application/json"
http.setRequestHeader "Accept", "application/json"
http.Send payload
If http.Status >= 200 And http.Status < 300 Then
Debug.Print http.ResponseText
Else
MsgBox "Request failed: " & http.Status & " " & http.statusText
End If
Exit Sub
Failed:
MsgBox "Could not reach the server: " & Err.Description
End Sub
To turn the response text into cells, see JSON in Excel VBA which uses the VBA-JSON library.
XMLHttpRequest vs WinHTTP
Both objects have the same Open, setRequestHeader and Send methods, so the code above works with either. Use CreateObject("WinHttp.WinHttpRequest.5.1") if you need proxy settings (SetProxy) or want to match a server that rejects MSXML. MSXML2.XMLHTTP is cached by Internet Explorer’s engine and can return stale responses; ServerXMLHTTP and WinHTTP are not, which is why the examples use ServerXMLHTTP.
Request headers
Request headers can be set using setRequestHeader method. Examples :
xmlhttp.setRequestHeader "Content-Type", "application/json"
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "User-Agent", "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"
xmlhttp.setRequestHeader "Authorization", AuthCredentials
Simple POST request to send formdata
POST requests are used to send some data, data can be sent in Send method. A simple POST request to send form data :
Public Sub httpclient()
Dim xmlhttp As New MSXML2.ServerXMLHTTP60, myurl As String
myurl = "https://httpbin.org/post"
xmlhttp.Open "POST", myurl, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.Send "name=codingislove&[email protected]"
MsgBox (xmlhttp.responseText)
End Sub
Basic Authentication in VBA
When we need to access web services with basic authentication, A username and password have to be sent with the Authorization header. Username and password should also be base64 encoded. Example :
user = "someusername"
password = "somepassword"
xmlhttp.setRequestHeader "Authorization", "Basic " + Base64Encode(user + ":" + password)
Practical use cases
Practical use cases of http requests in VBA are unlimited. Some of them are pulling data from Yahoo finance API, weather API, pulling orders from Ecommerce store admin panel, uploading products, retrieving web form data to excel etc.
Read : Parse HTML in Excel VBA - Learn by parsing hacker news home page where I retrieve a web page using HTTP GET request and parse its HTML to get data from a web page.
Read How to build a simple weather app in Excel VBA where I make a HTTP Get request to weather API
Read JSON Api in Excel VBA where I call JSON Apis using HTTP GET and POST requests.
FAQ
Which is better, XMLHttpRequest or WinHTTP in VBA? For most macros either works. ServerXMLHTTP is the usual choice; WinHTTP gives more control over proxies.
Why do I get a stale response? MSXML2.XMLHTTP can cache GET responses. Use ServerXMLHTTP or add a changing query string.
Does this work on Excel for Mac? No. These COM objects are Windows only.
If you have questions or feedback, comment below.
[mc4wp_form id=“177”]