Skip to main content

如何在Outlook中自動回覆包含原始郵件內容的郵件?

Author: Xiaoyang Last Modified: 2025-05-12

通常,當我們建立規則來自動回覆外出郵件時,郵件正文中不會包含原始郵件內容。那麼,該如何在Outlook中自動回覆並包含原始郵件內容呢?本文將介紹一段VBA代碼,幫助您在Outlook中快速完成此任務。

使用VBA代碼在Outlook中自動回覆帶有原始郵件內容的郵件


使用VBA代碼在Outlook中自動回覆帶有原始郵件內容的郵件

普通的Outlook規則無法幫助您處理這個問題,但使用以下VBA代碼,您可以快速輕鬆地完成此操作。請按照以下步驟進行:

1. 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

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

VBA代碼:自動回覆帶有原始郵件內容的郵件:

Public WithEvents xlItems As Outlook.Items
Private Sub Application_Startup()
    Set xlItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub xlItems_ItemAdd(ByVal objItem As Object)
Dim xlReply As MailItem
Dim xStr As String
If objItem.Class <> olMail Then Exit Sub
Set xlReply = objItem.Reply
With xlReply
     xStr = "<p>" & "Hi, Your email has been received. Thank you!" & "</p>"
     .HTMLBody = xStr & .HTMLBody
     .Send
End With
End Sub 
the screenshot of step 1 about using vba to auto reply with original email message in Outlook

3. 然後保存並關閉代碼窗口,關閉或重新啟動Outlook以使VBA代碼生效。現在,當您收到郵件時,Outlook將自動回覆並附帶原始郵件內容,如下方截圖所示:

the screenshot of step 2 about using vba to auto reply with original email message in Outlook