Obter taxas de câmbio - ajude-me a atualizar o URL no código VBA do Excel que costumava funcionar [fechado]
Eu estava usando esse código VBA que estava funcionando, agora a função retorna 0 porque a URL foi alterada. Que URL devo usar agora?
Muito obrigado
Function YahooCurrencyConverter(ByVal strFromCurrency, ByVal strToCurrency, Optional ByVal strResultType = "Value")
On Error GoTo ErrorHandler
'Init
Dim strURL As String
Dim objXMLHttp As Object
Dim strRes As String, dblRes As Double
Set objXMLHttp = CreateObject("MSXML2.ServerXMLHTTP")
strURL = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=c4l1&s=" & strFromCurrency & strToCurrency & "=X"
'Send XML request
With objXMLHttp
.Open "GET", strURL, False
.setRequestHeader "Content-Type", "application/x-www-form-URLEncoded"
.Send
strRes = .ResponseText
End With
'Parse response
dblRes = Val(Split(strRes, ",")(1))
Select Case strResultType
Case "Value": YahooCurrencyConverter = dblRes
Case Else: YahooCurrencyConverter = "1 " & strFromCurrency & " = " & dblRes & " " & strToCurrency
End Select
CleanExit:
Set objXMLHttp = Nothing
Exit Function
ErrorHandler:
YahooCurrencyConverter = 0
GoTo CleanExit
End Function