Skip to main content

如何在Outlook中批量將多封選定的郵件保存為MSG文件?

Author: Siluvia Last Modified: 2025-05-12

在Outlook中將單封郵件保存為MSG文件非常容易。那麼,如何在Outlook中批量將多封選定的郵件保存為單獨的MSG文件呢?本文將向您展示一種實現此操作的方法。

使用VBA代碼將多封選定的郵件保存為MSG文件


使用VBA代碼將多封選定的郵件保存為MSG文件

以下VBA代碼可以幫助您在Outlook中批量將多封選定的郵件保存為單獨的MSG文件。請按照以下步驟操作。

1. 選擇要保存為MSG文件的郵件。然後同時按下「Alt」+「F11」鍵以打開Microsoft Visual Basic for Applications窗口。

2. 在Microsoft Visual Basic for Applications窗口中,點擊「插入」>「模塊」,然後將以下VBA代碼複製到模塊窗口中。

VBA代碼:在Outlook中將多封選定的郵件保存為單獨的MSG文件

Public Sub SaveMessageAsMsg()
'Update by Extendoffice 2018/3/5
Dim xMail As Outlook.MailItem
Dim xObjItem As Object
Dim xPath As String
Dim xDtDate As Date
Dim xName, xFileName As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, strStartingFolder)
If Not TypeName(xFolder) = "Nothing" Then
    Set xFolderItem = xFolder.self
    xFileName = xFolderItem.Path & "\"
Else
    xFileName = ""
    Exit Sub
End If
For Each xObjItem In Outlook.ActiveExplorer.Selection
    If xObjItem.Class = olMail Then
        Set xMail = xObjItem
        xName = xMail.Subject
        xDtDate = xMail.ReceivedTime
        xName = Format(xDtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
          vbUseSystem) & Format(xDtDate, "-hhnnss", _
          vbUseSystemDayOfWeek, vbUseSystem) & "-" & xName & ".msg"
        xPath = xFileName + xName
        xMail.SaveAs xPath, olMSG
    End If
Next
End Sub

3. 按下「F5」鍵運行代碼。

4. 在「瀏覽文件夾」對話框中,請指定一個文件夾來保存MSG文件,然後點擊「確定」按鈕。請參見截圖:

the screenshot of step 1 about saving selected emails as msg files using vba in outlook

現在,所有選定的郵件都已保存為單獨的MSG文件,如下方截圖所示。

the screenshot of step 2 about saving selected emails as msg files using vba in outlook

輕鬆在Outlook中將選定的郵件保存為不同格式的文件:

借助「Kutools for Outlook」的「批量保存」工具,您可以輕鬆將多封選定的郵件保存為單獨的HTML格式文件、TXT格式文件、Word文檔、CSV文件以及PDF文件,如下方截圖所示。立即下載Kutools for Outlook的免費版本!

ad about saving emails as multiple file formats in outlook with kutools for outlook