以下代码从outlook中获取所有未分类的项目,但它返回所有项目,包括约会和会议。我需要一个代码,它只返回未分类的消息。
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
答案 0 :(得分:0)
您还需要将MessageClass属性检查包含在过滤器中。该属性返回一个字符串,表示Outlook项的消息类。
答案 1 :(得分:0)
以下代码对我有用。
Filter = "@SQL=" & Chr(34) & _
"urn:schemas-microsoft-com:office:office#Keywords" & _
Chr(34) & " is null"
Set ml = ml.Items.Restrict(Filter)
For i = ml.Count To 1 Step -1
If TypeOf ml(i) Is MailItem Then
End if
Next