以下代码已停止工作,因为URL已从:http://ec.europa.eu/taxation_customs/vies/services/checkVatService到:https://ec.europa.eu/taxation_customs/vies/#/vat-validation
为了修复代码,我应该更正什么?我将非常感谢您的帮助。
Sub VATCHECK()
Dim sURL As String
Dim sEnv As String
Dim xmlhttp As New MSXML2.xmlhttp
Dim xmlDoc As New MSXML2.DOMDocument 'DOMDocument
Dim sCountryCode As String
Dim sVATNo As String
Dim i As Long
On Error Resume Next
Range("D2", Range("D2").End(xlDown)).Clear
If Cells(Rows.Count, 1).End(xlUp).Row < 2 Then Exit Sub
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
sURL = "https://ec.europa.eu/taxation_customs/vies/#/vat-validation"
sCountryCode = Range("B" & i).Value
sVATNo = Range("C" & i).Value
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 Range("A" & i).Value = 0 Then
Range("D" & i).Value = ""
Else
If LCase(xmlDoc.getElementsByTagName("valid").Item(0).Text) = "true" Then
Range("D" & i).Value = "Valid VAT number"
Else
Range("D" & i).Value = "Invalid VAT number"
End If
End If
End With
Next i
End Sub
已更改URL,但代码仍然不起作用。
2条答案
按热度按时间cidc1ykv1#
On Error Resume Next
隐藏了以下错误:需要
这对我很有效:
tag5nh1u2#
我声明我正在处理有效的意大利增值税。
多亏了你的帮助(只是修改了对MSXML2.XMLHTTP60的引用),我成功地让脚本工作了。但是它不再提取地址和公司名称。我该怎么做呢?tks
结束子组件