Sub VATCHECK_WITH_SOAP()
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
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
If LCase(xmlDoc.getElementsByTagName("valid").Item(0).Text) = "true" Then
sname = Split(Split(.responseText, "<name>")(1), "</name>")(0)
sstreet = Split(Split(.responseText, "<address>")(1), "</address>")(0)
MsgBox "Valid VAT number : " & UCase(sCountryCode) & sVATNo & vbCrLf & _
sname & vbCrLf & _
sstreet, vbInformation
Else
MsgBox "Invalid VAT number : " & UCase(sCountryCode) & sVATNo, vbCritical
End If
End With
xmlhttp.abort
xmlDoc.abort
End Sub
|