将嵌套数组作为VBA中函数的参数传递会导致编译错误“Expected:=”

时间:2014-01-21 22:36:31

标签: excel function vba parameters multidimensional-array

我正在尝试构造一个数组(testSheets),它将文件名和文件路径保存为字符串。然后我希望在另一个数组(shtsTmpl)中包含这个数组。然后,我想将嵌套数组中的字符串传递给函数的参数(copySheets),以简单地返回msgbox中的组合文件路径。

第一段代码在msg框中成功返回“TSTSheets.xlsx”。

Sub prepSheets()
 Dim testSheets() As Variant
 ReDim testSheets(0)
 testSheets(0) = "TSTSheets.xlsx"

 Dim shtsTmpl() As Variant
 shtsTmpl = Array(testSheets)

 copySheets (shtsTmpl(0)(0))

End Sub

Function copySheets(srcName As String)
 MsgBox (srcName)
End Function

这第二段代码返回一个编译错误,在调用copySheets函数的行中显示“Expected:=”,我不明白为什么。

Sub testSheets()
 Dim testSheets() As Variant
 ReDim testSheets(1)
 testSheets(0) = "TSTSheets.xlsx"
 testSheets(1) = "C:\"

 Dim shtsTmpl() As Variant
 shtsTmpl = Array(testSheets)

 copySheets (shtsTmpl(0)(0),shtsTmpl(0)(1))
End Sub

Function copySheets(srcName As String, srcPath As String)
 MsgBox (srcPath & srcName)
End Function

有人可以向我解释为什么代码在函数有一个参数时正确编译而在函数有两个参数时错误编译?

如果您需要进一步说明,请与我们联系。

谢谢。

0 个答案:

没有答案