Excel

VAT checker for EU countries

Ease of Use

Easy

Version tested with

2013 32 bit 

Submitted by:

Charlize

Description:

This routing uses the 'soap' technique from the VIESS website to check if a VAT number exists and returns, if possible (depends on country), name and adress in a message box. 

Discussion:

When excel is you main program and you want a quick way to check the existence of a VAT number (required by law) maybe this routine can help. You can create a button on menu bar that calls this macro. 

Code:

instructions for use

			

Sub VATCHECK_WITH_SOAP() 'set reference to xml v3.0 Dim sURL As String Dim sEnv As String Dim sname As String, sstreet As String, spostcode As String, scity As String Set xmlhttp = CreateObject("MSXML2.XMLHTTP") Dim xmlDoc As New MSXML2.DOMDocument 'DOMDocument Dim sCountryCode As String Dim sVATNo As String sURL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService" sCountryCode = Application.InputBox("VAT Country Code : ", "VAT Country Code, ex. BE") sVATNo = Application.InputBox("VAT Number : ", "VAT Number ...") sEnv = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"">" sEnv = sEnv & "<soapenv:Header/>" sEnv = sEnv & "<soapenv:Body>" sEnv = sEnv & "<urn:checkVat>" sEnv = sEnv & "<urn:countryCode>" & sCountryCode & "</urn:countryCode>" sEnv = sEnv & "<urn:vatNumber>" & sVATNo & "</urn:vatNumber>" sEnv = sEnv & "</urn:checkVat>" sEnv = sEnv & "</soapenv:Body>" sEnv = sEnv & "</soapenv:Envelope>" With xmlhttp .Open "POST", sURL, False .setRequestHeader "Content-Type", "text/xml;" .send sEnv Set xmlDoc = New MSXML2.DOMDocument xmlDoc.LoadXML .responseText 'Check if VAT number exists If LCase(xmlDoc.getElementsByTagName("valid").Item(0).Text) = "true" Then 'split the responsetext by using the tags sname = Split(Split(.responseText, "<name>")(1), "</name>")(0) sstreet = Split(Split(.responseText, "<address>")(1), "</address>")(0) 'display messagebox with info MsgBox "Valid VAT number : " & UCase(sCountryCode) & sVATNo & vbCrLf & _ sname & vbCrLf & _ sstreet, vbInformation Else 'VAT number isn't valid MsgBox "Invalid VAT number : " & UCase(sCountryCode) & sVATNo, vbCritical End If End With xmlhttp.abort xmlDoc.abort End Sub

How to use:

  1. copy and paste this code in a module
  2. set a reference to xml v3.0
 

Test the code:

  1. In excel, press alt+f8, choose VATCHECK_WITH_SOAP, fill in a country code and a number.
  2. No error checking, so be sure to fill a landcode and number. VAT number can be wrong, you will be informed then.
 

Sample File:

No Attachment 

Approved by Jacob Hilderbrand


This entry has been viewed 17 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express