跳至主要内容

如何在Outlook中接受会议后自动分配颜色类别?

Author: Xiaoyang Last Modified: 2025-05-07

在日常工作中,您可能会在Outlook中收到多封会议邮件。有时,您希望在接受这些会议时自动为它们分配特定的颜色类别。通常情况下,您可以手动进行分配,但这样逐一设置会非常麻烦。本文将介绍如何在Outlook中自动完成这一操作。

使用VBA代码在接受会议后自动分配颜色类别


 使用VBA代码在接受会议后自动分配颜色类别

1. 按住“ALT + F11”键打开“Microsoft Visual Basic for Applications”窗口。

2. 在“Microsoft Visual Basic for Applications”窗口中,双击“Project1(VbaProject.OTM)”窗格中的“ThisOutlookSession”以打开模块,然后将以下代码复制并粘贴到空白模块中。

VBA代码:在接受会议后自动分配颜色类别

Public WithEvents SentItems As Outlook.Items
Private Sub Application_Startup()
    Set SentItems = Outlook.Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub SentItems_ItemAdd(ByVal Item As Object)
Dim xMeetingItem As Outlook.MeetingItem
Dim xMeetingItemAccepted As Outlook.MeetingItem
Dim xAppointmentItem As Outlook.AppointmentItem
On Error Resume Next
If TypeOf Item Is MeetingItem Then
    Set xMeetingItem = Item
    If InStr(xMeetingItem.Subject, "Accepted:") = 1 Then
        Set xMeetingItemAccepted = xMeetingItem
        Set xAppointmentItem = xMeetingItemAccepted.GetAssociatedAppointment(True)
        With xAppointmentItem
            .Categories = .Categories & "Red Category"
            .Save
        End With
    End If
End If
End Sub
doc auto categorize meetings 1

注意:在上述代码中,您可以将“红色类别”更改为所需的其他颜色类别名称。

3. 然后,重新启动Outlook以触发此宏。

4. 接受会议邮件后,点击“立即发送回复”选项,指定的颜色类别将立即分配给已接受的会议。请参见截图:

doc auto categorize meetings 2

注意:此代码仅适用于默认数据账户。