跳至主要内容

如何在Outlook中回复或转发邮件时保留类别?

Author: Xiaoyang Last Modified: 2025-05-07

通常,当您回复或转发已分类的邮件时,已发送邮件中的类别会自动被移除。如果您希望在回复或转发时保留外发邮件的类别,本文将介绍一种解决方法。

使用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