我正在尝试填充一个数组,但在每次迭代时增加了 dim 1 的元素大小,但是当我尝试时收到“下标超出范围消息”
ReDim Preserve sArray(1 To jTotal, 1 To UBound(sArray, 2))
有任何想法吗?
Dim j As Integer, jTotal As Integer
Dim eCount As Integer
ReDim sArray(1, 6)
For j = 1 To Application.Session.AddressLists.Item(AddList).AddressEntries.Count
On Error GoTo Err
If VBA.InStr(1, Application.Session.AddressLists.Item(AddList).AddressEntries.Item(j).GetExchangeUser.Department, _
fFilter, vbTextCompare) > 0 Then
jTotal = jTotal + 1
' '--> Redimensioning the array
ReDim Preserve sArray(1 To UBound(sArray, 1), 1 To UBound(sArray, 2))
'ReDim Preserve sArray(1 To jTotal, 1 To UBound(sArray, 2))
sArray(jTotal, 1) = j
sArray(jTotal, 2) = Application.Session.AddressLists.Item(AddList).AddressEntries.Item(j).Name
sArray(jTotal, 3) = Application.Session.AddressLists.Item(AddList).AddressEntries.Item(j).GetExchangeUser.Alias
sArray(jTotal, 4) = Application.Session.AddressLists.Item(AddList).AddressEntries.Item(j).GetExchangeUser.PrimarySmtpAddress
sArray(jTotal, 5) = Application.Session.AddressLists.Item(AddList).AddressEntries.Item(j).GetExchangeUser.BusinessTelephoneNumber
sArray(jTotal, 6) = Application.Session.AddressLists.Item(AddList).AddressEntries.Item(j).GetExchangeUser.Department
If Err.Number > 0 Then eCount = eCount + 1
End If
Next j