共用方式為


存取資料表中多重值屬性的值

一般而言,如果多重值屬性是使用其明確內建名稱新增至 Table ,則屬性值的格式會是以逗號分隔的字串。 如果多重值屬性使用命名空間參照新增至 Table,則屬性值的格式會是 Variant 陣列。

在下列程式碼範例中,會以參照屬性之名稱空間 urn:schemas-microsoft-com:office:office#Keywords 的名稱,將多重值 Categories 屬性新增至 Table。 為取得 Table 中每列的 Categories 欄值,會指定

oRow("urn:schemas-microsoft-com:office:office#Keywords")

給變數,並列舉變異陣列的元素。 請注意,對於尚未指派任何類別的專案,請指向變數,並列舉 variant 陣列的專案。 請注意,如果沒有指定任何類別給項目,則

oRow("urn:schemas-microsoft-com:office:office#Keywords")

會傳回空值。

Sub TableCategories() 
    Dim oT As Outlook.Table 
    Dim oRow As Outlook.Row 
    Dim varCat 
    Dim j As Integer 
    Dim strCategories As String 
 
    Set oT = Application.ActiveExplorer.CurrentFolder.GetTable() 
    oT.Columns.Add ("urn:schemas-microsoft-com:office:office#Keywords") 
    oT.Sort "LastModificationTime", True 
    Do Until oT.EndOfTable 
        Set oRow = oT.GetNextRow 
        'Obtain any values of the Categories property 
        varCat = oRow("urn:schemas-microsoft-com:office:office#Keywords") 
        If Not (IsEmpty(varCat)) Then 
            'Form a string out of the item's categories 
            For j = 0 To UBound(varCat) 
                strCategories = strCategories & (varCat(j)) & ", " 
            Next 
            'Remove last trailing ", " 
            strCategories = Left(strCategories, Len(strCategories) - 2) 
        Else 
            'The item does not have any categories 
            strCategories = "" 
        End If 
        Debug.Print ("Subject: " _ 
           & oRow("Subject") & vbCrLf & "Categories: ") & strCategories & vbCrLf 
    Loop 
End Sub

支援和意見反應

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