Table.GetArray 方法 (Outlook)
获取一个二维数组,该数组中包含 Table 中的一组行值和列值。
语法
expression。 GetArray
( _MaxRows_
)
表达 一个代表 Table 对象的变量。
参数
名称 | 必需/可选 | 数据类型 | 说明 |
---|---|---|---|
MaxRows | 必需 | 长整型 | 指定要返回 表 中的行的最大数目。 |
返回值
Variant值,表示 表 中的一组行和列的值的二维数组。 该数组是从零开始;数组中的第 i 和第 j 列行的数组索引 (i,j) 索引。 数组中的列相对应的 表 中的列和行数组中的对应于 表 中的行。 返回的数组中的行数是 MaxRows和 Table中的行的实际数目小的值。
备注
无效 方法提供了一种将全部或部分 (基于当前行) 表 中的数据复制到一个数组,该数组的索引的 表 中获取值的概念上很简单方法。
无效 总 表 的当前行开始。 如果表中至少有从当前位置开始的行数 MaxRows,则返回一个数组,其中包含 MaxRows 行数。 如果 MaxRows 不大于 Table 中的总行数,并且表中从当前行开始的元素数少于 MaxRows 数,则它将返回一个仅包含 Table 中剩余行的数组。 如果调用 无效 ,并且没有剩余的行,则 无效 返回包含零个元素的空数组。
在 表 中,并在它返回之前获得相应的行后, 无效 始终将重新定位当前行与下一行在 表 中,如果存在下一行。 GetArray(n)
操作如同 Table.GetNextRow 称为 n 倍。
列中的值映射到 表 中的列,因此由用于列的属性名称的格式。 有关详细信息,请参阅影响 Table 类和 View 类中属性值表示方式的因素。
示例
下面的代码示例获取 表 通过筛选在收件箱中所有主题中包含"办公室"的项目上。 然后使用 Table.GetArray 方法将 表 的数据复制到一个数组中,并将打印的每个项返回的属性值。
有关在筛选器中通过命名空间引用指定属性名称的详细信息,请参阅通过命名空间引用属性。
Sub DemoTableUsingGetArray()
'Declarations
Dim Filter As String
Dim i, ubRows As Long
Dim j, ubCols As Integer
Dim varArray
Dim oTable As Outlook.Table
Dim oFolder As Outlook.Folder
Const SchemaPropTag As String = _
"http://schemas.microsoft.com/mapi/proptag/"
On Error Resume Next
'Get a Folder object for the Inbox
Set oFolder = Application.Session.GetDefaultFolder(olFolderInbox)
'Filter on the subject containing "Office"
Filter = "@SQL=" & Chr(34) & SchemaPropTag & "0x0037001E" _
& Chr(34) & " like '%Office%'"
'Get all items in Inbox that meet the filter
Set oTable = oFolder.GetTable(Filter)
On Error GoTo Err_Trap
varArray = oTable.GetArray(oTable.GetRowCount)
'Number of rows is the second dimension of the array
ubRows = UBound(varArray, 2)
'Number of columns is the first dimension of the array
ubCols = UBound(varArray)
'Array is zero-based
'Rows corrspond to items in the table, so for each item...
For j = 0 To ubRows
'Columns correspond to properties in the table, print the value of each property
For i = 0 To ubCols
Debug.Print varArray(i, j)
Next
Next
Exit Sub
Err_Trap:
Debug.Print "Error#:" & Err.Number & " Desc: " & Err.Description
Resume Next
End Sub
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。