基于类别的电子邮件计数

时间:2013-06-04 08:46:05

标签: vba count outlook categories

我与我公司的MS Exchange相关联。从我自己的Outlook配置文件中,我访问一个通用邮箱。所有传入的邮件都会被标记为一个类别,然后移动到一个文件夹( 邮箱 - 通用>已解决 )。如何生成此文件夹中每个类别的总数?

邮箱 - Javen

  • 收件箱
  • 已发送物品
  • ...

邮箱 - 通用

  • 收件箱
  • 已发送物品
  • 解决
  • ...

每个类别都将命名为名称......

示例:红色=约翰,黄色=彼得,紫色=佩吉

1 个答案:

答案 0 :(得分:2)

这应该让你去。它会过滤指定类别的文件夹。您可以对其进行编辑以执行Outlook Categories集合的循环以获取计数。或者您可以将其更改为返回计数的函数...将类别名称作为参数传递。

Private Sub CountbyCategory()
    Dim fldr As Outlook.Folder = Nothing
    Dim itms As Outlook.Items = Nothing
    Dim filteredItms As Outlook.Items = Nothing


    'Do this for each category...
    Dim typeFilter As String = "[Category] = " & Chr(39) & "INSERT CATEGORY NAME HERE" & Chr(39)

    'This assumes default inbox, you'll need to select you folder...maybe use PickFolder?
    'fldr = Application.Session.PickFolder()
    fldr = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    itms = fldr.Items
    filteredItms = itms.Restrict(typeFilter)

    Dim iCount As Integer = filteredItms.Count

    'Repeat for each category
End Sub

您可以在此处详细了解如何使用Outlook项目: Working with Outlook mail items: how to create, delete, access & enumerate

Working with Outlook Accounts, Stores, Folders and Items