MS Excel - How to call a SOAP web service
Master calling SOAP web services from MS Excel using VBA. Get the code and a step-by-step tutorial to validate VAT numbers with the VIES service.
This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.
This article is part of the VBA & MS Office automation series:
- MS Office - How to create a ribbon in Excel
- MS Excel - How to call a SOAP web service
- How to optimize an existing MS Access database
- VBS - Retrieve the list of fields in a MS Access Database
- VBS - Auto update script
- Microsoft Outlook - VBA - Save emails as PDF
- VBS - Get list of files and generate a CSV
- MS Office - Load dropdown from Excel's range
- Export MS Access objects
- MS Excel - Get the list of references used in your modules

This article shows a VBA skeleton for calling a SOAP web service from Excel, using the EU's VIES VAT number validation service as a concrete example: building an XML request file with placeholders, sending it via MSXML2.ServerXMLHTTP60, and opening the XML response as a new workbook. A Linux curl-based equivalent is also included for comparison.
Imagine you had to make a call to a SOAP web service in Excel? For example, to validate the VAT number you have been given before carrying out some processing.
You will call the URL that corresponds to the web service you want, but you will also need to pass a number of parameters in XML format so that the service knows what you want to do.
We'll learn, in this blog post, how to validate a European VAT number using the VIES VAT number validation SOAP web service.
The VBA code we will see in this article can be used as a skeleton for your future development.
That same VIES service is used as the running example in Using Postman to play with API, where the XML response is asserted node by node — a good way to understand a SOAP answer before writing the VBA that parses it.
So, when calling a SOAP service, we must always prepare an XML message first. To do this, we create an .xml file somewhere on our hard drive.
Create the xml message
Please create the file C:\temp\checkVat.xml with this content. This message (content) is expected by the VIES VAT number web service. In the file, we foresee two placeholders for our variables: %COUNTRY% and %VATNUMBER%. We'll see this later on.
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <urn:checkVat xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> <urn:countryCode>%COUNTRY%</urn:countryCode> <urn:vatNumber>%VATNUMBER%</urn:vatNumber> </urn:checkVat> </soapenv:Body></soapenv:Envelope>This is a SOAP request template for validating a VAT (Value Added Tax) number against the European Commission's VIES database. It wraps a checkVat service call with placeholder values that will be substituted with an actual country code and VAT number at runtime.
Create the Excel workbook
Now, please,
- Create an empty Excel workbook,
- Press ALT-F11 to get the Visual Basic Editor (aka
vbe). - Create a new module:

- Copy/Paste the VBA code from here below to it.
- Check the path for the
InputXmlFileconstant. Make sure it's the same as where you've saved your.xmlfile earlier. - Click on the
Toolsmenu then selectReferencesand add a reference toMicrosoft XML, v6.0
- Finally, put the cursor anywhere in the
runsubroutine and press F5 to run it.
- After a few seconds, a new workbook will be created with the answer from the SOAP web service:

Option Explicit
' URL to call
Const URL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
' XML to send to the web service method
Const InputXmlFile = "C:\temp\checkVat.xml"
' *************************************************************
'
' Entry point
'
' - Call the web service checkVAT method
' - Upload XML data (country and VAT number)
' - Get XML response
' - Open the response as a workbook
'
' *************************************************************
Sub run()
Dim sData As String
Dim sResponseFileName As String
' Get the input manifest
sData = openCheckVatXml(InputXmlFile)
' Consume the web service and get a filename with the response
If (sData = "") Then
MsgBox "Failure, the " & InputXmlFile & " file didn't exist", vbExclamation + vbOKOnly
Exit Sub
End If
sResponseFileName = consumeWebService(URL, sData)
' Open the response as a workbook
Call Application.Workbooks.OpenXML(Filename:=sResponseFileName)
End Sub
' *************************************************************
'
' Open the checkVat.xml input and replace variables
'
' *************************************************************
Private Function openCheckVatXml(ByVal sFileName As String) As String
Dim sData As String
sData = readFile(sFileName)
If (sData <> "") Then
sData = Replace(sData, "%COUNTRY%", "BE")
sData = Replace(sData, "%VATNUMBER%", "0403170701") ' ENGIE Electrabel Belgique
End If
openCheckVatXml = sData
End Function
' *************************************************************
'
' Generic file reader. Return the content of the text file
'
' *************************************************************
Private Function readFile(ByVal sFileName As String) As String
Dim objFso As Object
Dim objFile As Object
Dim sContent As String
Set objFso = CreateObject("Scripting.FileSystemObject")
If Not (objFso.FileExists(sFileName)) Then
' The file didn't exist
readFile = ""
Exit Function
End If
Set objFile = objFso.OpenTextFile(sFileName, 1)
sContent = objFile.readAll
objFile.Close
Set objFile = Nothing
Set objFso = Nothing
readFile = sContent
End Function
' *************************************************************
'
' Return a filename with the response of the web service method
'
' *************************************************************
Private Function consumeWebService(ByVal sURL As String, ByVal sData As String) As String
Dim xmlhttp As Object
Dim sResponseFileName As String
Set xmlhttp = New MSXML2.ServerXMLHTTP60 ' Requires Microsoft XML, v6.0
xmlhttp.Open "POST", sURL, True
xmlhttp.send sData
xmlhttp.waitForResponse
sResponseFileName = createXmlTempFile(xmlhttp.responseText)
Set xmlhttp = Nothing
consumeWebService = sResponseFileName
End Function
' *************************************************************
'
' Create a temporary file in the TEMP folder and write in that
' file the XML response received by the web service.
'
' Return the temporary filename as result of this function
'
' *************************************************************
Private Function createXmlTempFile(ByVal sContent As String) As String
Dim objFso As Object
Dim objFile As Object
Dim objFolder As Object
Dim sFileName As String
Set objFso = CreateObject("Scripting.FileSystemObject")
' 2 = temporary folder
Set objFolder = objFso.GetSpecialFolder(2)
sFileName = objFolder & "\"
Set objFolder = Nothing
sFileName = sFileName & objFso.GetTempName()
sFileName = Replace(sFileName, ".tmp", ".xml")
Set objFile = objFso.CreateTextFile(sFileName)
objFile.Write sContent
objFile.Close
Set objFile = Nothing
Set objFso = Nothing
createXmlTempFile = sFileName
End Function
About placeholders
In our C:\temp\checkVat.xml, we've thus foreseen two placeholders.
You can see in the openCheckVatXml VBA subroutine how we'll replace them by some, example, values. Just adjust them to yours.
A Linux command-line version
For those who can be interested, here is another way to achieve the same result but for a Linux console (or DOS if you've curl installed):
curl --silent http://ec.europa.eu/taxation_customs/vies/services/checkVatService \
-w \\n \
-H 'SOAPAction: "checkVat"' \
-H "Content-Type: text/xml;charset=UTF-8" \
-d '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<urn:checkVat xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
<urn:countryCode>BE</urn:countryCode>
<urn:vatNumber>0403170701</urn:vatNumber>
</urn:checkVat>
</soapenv:Body>
</soapenv:Envelope>'
Add `xmlstarlet` for a nice output
See my The xmlstarlet utility for Linux article.
Add | xmlstarlet format --indent-spaces 4 at the end of the previous command to pipe the output to xmlstarlet (see The xmlstarlet utility for Linux)
The answer will be:
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<ns2:checkVatResponse xmlns:ns2="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
<ns2:countryCode>BE</ns2:countryCode>
<ns2:vatNumber>0403170701</ns2:vatNumber>
<ns2:requestDate>2024-01-07+01:00</ns2:requestDate>
<ns2:valid>true</ns2:valid>
<ns2:name>SA ELECTRABEL</ns2:name>
<ns2:address>Boulevard Simon Bolivar 36\n1000 Bruxelles</ns2:address>
</ns2:checkVatResponse>
</env:Body>
</env:Envelope>
Now, it's up to you to modify the VBA code and tailor it to your needs.
If you're designing the API side of things rather than just consuming it, see API REST - How to write good APIs for general API design context.
This article is part of the VBA & MS Office automation series:
- MS Office - How to create a ribbon in Excel
- MS Excel - How to call a SOAP web service
- How to optimize an existing MS Access database
- VBS - Retrieve the list of fields in a MS Access Database
- VBS - Auto update script
- Microsoft Outlook - VBA - Save emails as PDF
- VBS - Get list of files and generate a CSV
- MS Office - Load dropdown from Excel's range
- Export MS Access objects
- MS Excel - Get the list of references used in your modules




