共用方式為


篩選沒有類別的專案

本主題示範的程式碼範例會使用 DAV 搜尋和尋找 (DASL) 查詢來篩選目前資料夾中未指派任何類別的專案。 請注意,篩選空字串類別的項目時,需要 DASL 查詢;Microsoft Jet 語法不支援這種篩選。

使用 DASL 查詢篩選空字串時,您可以使用 Is Null 關鍵字。 Is Null 運算可用來判斷字串屬性是否為空白,或日期屬性是否已設定。 如需詳細資訊,請參閱使用查詢關鍵字篩選項目

程式碼範例會在 Categories 屬性上設定 DASL 篩選,該屬性在 DASL 查詢中是以 Office 命名空間表示為 urn:schemas-microsoft-com:office:office#Keywords。 篩選準則會使用Is Null關鍵字,將Categories屬性的值與空字串進行比較。 然後,程式碼範例將篩選套用至目前資料夾中的項目。 最後,它會列印目前資料夾中不具類別的項目數目。

Sub NullCategoryRestriction() 
 Dim oFolder As Outlook.Folder 
 Dim oItems As Outlook.Items 
 Dim Filter As String 
 
 'DASL Filter can test for null property. 
 'This will return all items that have no category. 
 Filter = "@SQL=" & Chr(34) & _ 
 "urn:schemas-microsoft-com:office:office#Keywords" & _ 
 Chr(34) & " is null" 
 Set oFolder = Application.ActiveExplorer.CurrentFolder 
 Set oItems = oFolder.Items.Restrict(Filter) 
 Debug.Print oItems.Count 
End Sub

支援和意見反應

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