在所选单元格上手动运行功能


0

如何解决传递给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

请发布您的ExchangeRatesCalc代码。
Gary的学生

任何想法都赞赏。
user2319146 2016年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.