在Excel VBA中声明和初始化数组

时间:2016-04-21 12:57:55

标签: excel-vba vba excel

任何人都可以向我解释为什么会这样:

Dim myArr As Variant `or, myArr()`
myArr = Array("Brian", "Steve", "Dan", "Mark", "Tom")

这并不是:

Dim myArr As String
myArr = Array("Brian", "Steve", "Dan", "Mark", "Tom")

我收到运行时错误' 13':类型不匹配

1 个答案:

答案 0 :(得分:2)

这是因为函数Array返回Variant

https://msdn.microsoft.com/en-us/library/aa262675(v=vs.60).aspx