其他分享
首页 > 其他分享> > 货币汇率查询vba

货币汇率查询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

标签:result,vba,responseText,String,url,查询,货币汇率,ex,cur
来源: https://www.cnblogs.com/bluefallyou/p/16390080.html