【问题标题】:Add a category for all selected emails using Outlook VBA使用 Outlook VBA 为所有选定的电子邮件添加一个类别
【发布时间】:2021-01-01 03:32:57
【问题描述】:

我正在尝试为使用 VBA 在 Outlook 中选择的每封电子邮件添加一个类别。

问题在于下面的代码仅将类别添加到第一电子邮件。

我正在使用 Outlook 2016。

Public Sub MarkSelectedAsGreenCategory()
    Dim olItem As MailItem
    
    Dim newCategory As String
    newCategory = "Green category"
    
    Dim i As Integer
    
    For i = 1 To Application.ActiveExplorer.Selection.Count
        Set olItem = Application.ActiveExplorer.Selection(i)
        AddCategory olItem, newCategory
        Set olItem = Nothing
    Next
      
End Sub

Private Sub AddCategory(mailItem As mailItem, newCategory As String)
    Dim categories() As String
    Dim listSep As String

    ' Get the current list separator from Windows regional settings
    listSep = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Control Panel\International\sList")

    ' Break the list up into an array
    categories = Split(mailItem.categories, listSep)

    ' Search the array for the new category, and if it is missing, then add it
    If UBound(Filter(categories, newCategory)) = -1 Then
        ReDim Preserve categories(UBound(categories) + 1)
        categories(UBound(categories)) = newCategory
        mailItem.categories = Join(categories, listSep)
    End If
End Sub

【问题讨论】:

    标签: vba outlook outlook-2016 office-2016


    【解决方案1】:

    更新ActiveInspector.CurrentItem 上的类别会提示保存。

    对于一个选择:

    olItem.SavemailItem.Save 在您方便的时候使用。

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 2014-12-31
      • 2012-03-07
      • 1970-01-01
      相关资源
      最近更新 更多