Я пытаюсь получить данные во многих валютах и конвертировать их все в евро. Я нашел код на этом сайте, но код слишком сложен для меня и его невозможно отлаживать с моими знаниями.
Я выделил ошибку, когда код достигает xhr.send. У вас есть идеи, почему это могло произойти?
Я не понимаю, что делает эта часть, поэтому мне трудно ее отлаживать.
Сообщение об ошибке, которое я получаю, выглядит следующим образом:
Ошибка выполнения "-2147012889 (80072ee7)" Ошибка автоматизации
Sub test()
Dim test1 As Variant
test1 = ConvCurrency(1, "USD", "GBP")
MsgBox (test1)
End Sub
''
' UDF to convert a currency using the daily updated rates fron the European Central Bank '
' =ConvCurrency(1, "USD", "GBP") '
''
Public Function ConvCurrency(Value, fromSymbol As String, toSymbol As String)
Static rates As Collection, expiration As Date ' cached / keeps the value between calls '
If DateTime.Now > expiration Then
Dim xhr As Object, node As Object
expiration = DateTime.Now + DateTime.TimeSerial(1, 0, 0) ' + 1 hour '
Set rates = New Collection
rates.Add 1#, "EUR"
Set xhr = CreateObject("Msxml2.ServerXMLHTTP.6.0")
xhr.Open "GET", "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml", False
xhr.Send
For Each node In xhr.responseXML.SelectNodes("//*[@rate]")
rates.Add Conversion.Val(node.GetAttribute("rate")), node.GetAttribute("currency")
Next
End If
ConvCurrency = (Value / rates(fromSymbol)) * rates(toSymbol)
End Function
РЕДАКТИРОВАТЬ: для любого будущего читателя я изменил свой объект на msxml2.xmlhttp, теперь он работает.
0.773935715506924
. Может быть, проблема с сетью, специфичная для Excel, на вашей стороне, например, проблема с конфигурацией прокси-сервера или брандмауэра? - person ƬƦƖƝƛ   schedule 16.10.2020