VBA—数组的定义与声明
的有关信息介绍如下:数组在VBA宏代码操作中具有重要作用,下面介绍数组的定义与声明。
定义数组:
一维数组
Dim array_name(n) As type
其中n是数组中的元素的数目-1。
多维数组
Dim iTable(3,3) As Integer
动态数组
Dim dyn_array() As type
用ReDim语句指定数组的大小:ReDim dyn_array(array_size)
如果要保留数组的数值,在ReDim语句后使用保留字Preserve,具体语法如下:
ReDim Preserve dyn_array(arraysize)