1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Public Function checkVAT(ByVal CountryCode As String, ByVal vatNumber As String, Optional ByRef isErr As Boolean) As Boolean
'Validation du numéro de TVA via VIES : http://ec.europa.eu/taxation_customs/vies/vatRequest.html
On Error GoTo fin
Const cURL As String = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
Const cEnv As String = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" & _
"<env:Body><cv:checkVat xmlns:cv='urn:ec.europa.eu:taxud:vies:services:checkVat:types'>" & _
"<cv:countryCode>CC</cv:countryCode><cv:vatNumber>VN</cv:vatNumber>" & _
"</cv:checkVat></env:Body></env:Envelope>"
Dim sEnv As String, sResult As String, oHttp As Object
isErr = True
sEnv = Replace(Replace(cEnv, "CC", CountryCode, , , vbBinaryCompare), "VN", vatNumber, , , vbBinaryCompare)
Set oHttp = CreateObject("MSXML2.XMLHTTP")
oHttp.Open "POST", cURL, False: oHttp.send sEnv
If oHttp.Status = 200 Then
sResult = getTextBetween(oHttp.responseText, "<valid>", "</valid>")
checkVAT = (sResult = "true")
isErr = False
End If
fin:
Set oHttp = Nothing
End Function
'retourne un texte entre deux limites
Private Function getTextBetween(ByVal text As String, ByVal Before As String, Optional ByVal After As String = " ") As String
On Error Resume Next
getTextBetween = Split(Split(text, Before)(1), After)(0)
End Function |
Partager