将paramarray传递到需要paramarray的功能

时间:2017-01-10 06:43:06

标签: excel vba

在excel-vba中,如何将一个paramarray传递给一个期望相同的paramarray的函数?我一直在四处寻找,但似乎找不到这个具体问题的答案

我的代码如下所示:

Sub test()
    GetRefData "SPX Index", "PX_LAST", "PX_VOLUME", "PE_RATIO", "PX_TO_CASH_FLOW"
End Sub

Public Function GetRefData(security As String, ParamArray fields() As Variant) As String
    Debug.Print fields(0) // returns "PX_LAST"
    SendReq security, fields
End Function

Sub SendReq(security, ParamArray fields() As Variant)
    Debug.Print fields(0) // returns type mismatch
End Sub

1 个答案:

答案 0 :(得分:0)

在查找the article Tim posted之后,解决方案是,当作为参数传递时,必须更深层次地访问参数,即:

Sub SendReq(security, ParamArray fields() As Variant)
    Debug.Print fields(0)(0)
End Sub