Skip to main content

如何在Outlook中接受會議後自動分配顏色類別?

Author: Xiaoyang Last Modified: 2025-05-12

在日常工作中,您可能會在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

注意:此代碼僅適用於預設數據帳戶。