我有这组VBA功能:
Sub x()
Dim a() As Variant
z y(a)
End Sub
Function y(a() As Variant) As Variant
y = a
End Function
Function z(a() As Variant) As Variant
z = a
End Function
当我运行x()
时,行z y(a)
会引发错误:
Type mismatch: array or user-defined type expected
我想是因为z()
期望将数组作为参数,但是y()
的返回值是一个变量,而不是数组。我不确定如何明确说明y()
返回一个变量数组-我是否声明错误?
答案 0 :(得分:1)
尽管您的代码不执行任何操作,但这将停止错误:
Sub x()
Dim a() As Variant
z y(a)
End Sub
Function y(a() As Variant) As Variant()
y = a
End Function
Function z(a() As Variant) As Variant()
z = a
End Function