相关文章推荐
彷徨的匕首  ·  Use data operations ...·  1 月前    · 
不羁的领带  ·  kafka ...·  1 年前    · 
爽快的充电器  ·  java stream ...·  1 年前    · 
欢乐的骆驼  ·  mediaplayer seekto 无效-掘金·  2 年前    · 

Variant 值,代表 Table 中的一組資料列和資料行 值的二 維陣列。 陣列是以零起始;陣列索引 (i、j 將索引) 到陣列中的第 i 個數據行和第 j 個數據列。 陣列中的資料行會對應至 Table 中的資料行,而陣列中的資料列會對應至 Table 中的資料 。 傳回陣列中的資料列數目是 MaxRows 的較小值,以及 Table 中的實際資料列數目。

GetArray 方法提供一項在概念上相當簡單的方式,藉由將 Table 中的所有或部分資料 (根據目前的列) 複製到陣列並索引陣列,取得 Table 中的值。

GetArray 一定會從 Table 的目前列開始。 如果 Table 中至少有從目前 位置開始的 MaxRows 資料列數目,則會傳回具有 MaxRows 資料列數目的陣列。 如果 MaxRows 不大於 Table 中的資料列總數,而且從目前資料列開始, Table 中的元素數目少於 MaxRows ,則會傳回只包含 Table 中其餘資料列的陣列。 如果呼叫 GetArray 時,沒有其餘列, GetArray 就會傳回零個元素的空陣列。

Table 取得適當的列之後並在其傳回之前, GetArray 一定會將目前列的位置重新調整為 Table 中的下一列 (如果下一列存在的話)。 GetArray(n) 的運作方式就如 同 Table.GetNextRow 呼叫 n 次一樣。

欄中的值會對應至 Table 中的欄,因此會由欄所用的屬性名稱格式決定。 如需詳細資訊,請參閱 影響 Table 及 View 類別之屬性值表示的因素

下列程式碼範例會篩選主旨中包含 「Office」 之收件匣中的所有專案,以取得資料 。 然後,它會使用 Table.GetArray 方法,將 Table 中的資料複製到陣列,並列印每一個傳回項目的屬性值。

如需依命名空間參照在篩選條件中指定屬性名稱的詳細資訊,請參閱 依命名空間參照屬性

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) 
 Exit Sub 
Err_Trap: 
 Debug.Print "Error#:" & Err.Number & " Desc: " & Err.Description 
 Resume Next 
End Sub

Table 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應