Skip to main content

如何在 Outlook 中回覆或轉寄郵件時保留類別?

Author: Xiaoyang Last Modified: 2025-05-12

通常,當您回覆或轉寄已分類的郵件時,已傳送郵件中的類別會自動刪除。若您希望在回覆或轉寄時保留外寄郵件的類別,本文將介紹一種處理方法。

使用 VBA 程式碼在回覆或轉寄郵件時保留類別


使用 VBA 程式碼在回覆或轉寄郵件時保留類別

1. 按住 ALT + F11 鍵以開啟 Microsoft Visual Basic for Applications 視窗。

2. 在 Microsoft Visual Basic for Applications 視窗中,於 Project1(VbaProject.OTM) 窗格中雙擊 ThisOutlookSession 以打開模組,然後複製並將以下程式碼貼到空白模組中。

VBA 程式碼:在回覆或轉寄郵件時保留類別:

Private WithEvents GExplorer As Outlook.Explorer
Private WithEvents GInspectors As Outlook.Inspectors
Private WithEvents GMailItem As Outlook.MailItem
Private GCategories As String
Private Sub Application_Startup()
    Dim xApp As Outlook.Application
    Set xApp = Outlook.Application
    Set GExplorer = xApp.ActiveExplorer
    Set GInspectors = xApp.Inspectors
End Sub
Private Sub GExplorer_SelectionChange()
    On Error Resume Next
    If TypeName(GExplorer.Selection.Item(1)) <> "MailItem" Then Exit Sub
    Set GMailItem = GExplorer.Selection.Item(1)
    GCategories = GMailItem.Categories
End Sub
Private Sub GInspectors_NewInspector(ByVal Inspector As Inspector)
    On Error Resume Next
    If TypeName(Inspector.CurrentItem) <> "MailItem" Then Exit Sub
   Set GMailItem = Inspector.CurrentItem
    GCategories = GMailItem.Categories
End Sub
Private Sub GMailItem_Forward(ByVal Forward As Object, Cancel As Boolean)
    Call GetCategories(Forward)
End Sub
Private Sub GMailItem_Reply(ByVal Response As Object, Cancel As Boolean)
    Call GetCategories(Response)
End Sub
Private Sub GMailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
    Call GetCategories(Response)
End Sub
Private Sub GetCategories(ByVal NewMail As Object)
    If NewMail.Class <> olMail Then Exit Sub
    NewMail.Categories = GCategories
End Sub
doc keep category reply 1

3. 接著保存並關閉此程式碼視窗,關閉並重新啟動 Outlook,現在,當您回覆或轉寄帶有類別的郵件時,該類別將保留在已傳送郵件中的外寄郵件內,請參見截圖:

doc keep category reply 2