如何解决传递给ExchangeRatesCalc(应该是字符串)的参数的类型不匹配错误?
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("ExchangeRates[XRT]")) Is Nothing Then
Call ExchangeRatesCalc("ExchangeRates[Currency]")
End If
End If
End Sub
ExchangeRates是一个格式化的表; XRT和货币是表格中的列。当我单击XRT中的单元格时,我想将相应的Currency传递给ExchangeRatesCalc,并将结果显示在XRT中。
Option Explicit
Function ExchangeRatesCalc(DestCur As String) As Variant
' Requires Microsoft WinHTTP Services reference
Dim url As String
' http://quote.yahoo.com/d/quotes.csv?s=XXXYYY=X&f=l1
url = "http://quote.yahoo.com/d/quotes.csv?s=USD" & DestCur & "=X&f=l1"
Dim myHTTP As New WinHttp.WinHttpRequest
myHTTP.Open "GET", url, False
myHTTP.send ""
If myHTTP.StatusText <> "OK" Then GoTo ServerErrorHandler
If Not (WorksheetFunction.IsNumber(myHTTP.responseText)) Then ExchangeRatesCalc = 0
' This is where the error occurs
ExchangeRatesCalc = CDbl(myHTTP.responseText)
Exit Function
ServerErrorHandler:
MsgBox "Error. Could not convert currency"
End Function
任何想法都赞赏。
—
user2319146 2016年
ExchangeRatesCalc代码。