如何使用vba

时间:2016-01-25 12:14:55

标签: vba email outlook

创建一个宏,从outlook中的所有未分类的消息中提取一些数据。我可以通过使用循环并检查收件箱中每封邮件的状态来获取数据,但收件箱中的邮件数量很大。那么有没有办法过滤未分类的项目,然后从过滤的邮件中获取数据。

我尝试了以下代码。然而它不适合我。

Mailbox = Cells(k, 1).Value

Set Fldr = olNs.Folders(Mailbox).Folders("inbox")
Fldr.Items.Restrict ("[Category]=[]")

有没有办法可以加速宏。

1 个答案:

答案 0 :(得分:1)

这描述了如何“Filter Items that Do Not Have 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