Home > OS >  Having Trouble filtering mails in Outlook with certain Categories with VBA
Having Trouble filtering mails in Outlook with certain Categories with VBA

Time:12-07

I have hundreds of mails in inbox and they can have any combination of mutiple categories ("AA","BB","CC","DD", etc.) which can be assigned in any order. I want to select mails using only .Items.Restrict to filter mails that have "AA" and NOT have "BB", no matter if other categories are set or not. I'm trying to avoid looping all mails to check the .categories text string, which is a way to go but very slow. I tried someting like this with no luck:

    sFilter = "[Categories] = 'AA' And Not([Categories] = 'BB')"
    Set oOlResults = oOlInb.Items.Restrict(sFilter)

Is that possible? Any help will be appreciated.

CodePudding user response:

All possible combinations that do not include category BB.

sfilter = "[Categories] = 'AA' OR [Categories] = 'AA, CC' OR [Categories] = 'CC, AA'"

CodePudding user response:

Trying to help someone with this same problem I will post what I've just found: this can be solved using DASL filter string. For this example:

sFilter = "@SQL=""urn:schemas-microsoft-com:office:office#Keywords"" like 'AA' AND NOT (""urn:schemas-microsoft-com:office:office#Keywords"" like 'BB')"
  • Related