货币汇率查询vba

'1 ex exchange to how many cur
Function GetExchangeRate(ex As String, cur As String) As String

On Error GoTo Err

Dim url, oHttp, responseText, result, exchangeRate As String

If ex = "" Then ex = "USD"
If cur = "" Then cur = "CNY"

'crawl data from URL
url = "https://qq.ip138.com/hl.asp?from=" & ex & "&to=" & cur & "&q=100"
Set oHttp = CreateObject("MSXML2.XMLHTTP")
With oHttp
.Open "GET", url, False
.send
responseText = .responseText
Debug.Print responseText
End With

'get exchange rate
result = Split(Split(responseText, "</p></td><td><p>")(2), "<td><p>")(2)
exchangeRate = Left(result, 8)

GetExchangeRate = exchangeRate
Exit Function
Err:
MsgBox "Can't get Exchange-Rate !"
End Function

posted @ 2022-06-19 10:42  B4U  阅读(389)  评论(0)    收藏  举报