How to Batch Export Multiple Outlook Emails into One Word Document via VBA

If you want to batch export multiple Outlook emails into a single word document, you can use the VBA code shown in this article. It can assist you to accomplish this task within seconds.

I have ever introduced how to convert an Outlook email into a Word document in my previous article – “2 Effective Methods to Convert an Outlook Email to a Word document”. However, both the 2 means mentioned in that post will be helpless in the case where you desire to batch export many emails into one Word document. Hence, here we will teach you another way. Now, read on to get it elaborately.

Batch Export Multiple Outlook Emails into One Word Document via VBA

Batch Export Multiple Outlook Emails into One Word Document

  1. To start with, launch your Outlook program.
  2. Then, after entering the main Outlook window, you need to press “Alt + F11” key buttons.
  3. Next you will get access to Outlook VBA editor, in which you ought to open a blank module.
  4. Subsequently, copy the VBA code below into the opened module window.
Sub ExportMultipleEmails_OneWordDocument()
    Dim objFileSystem As Object
    Dim strTempFolder As String
    Dim objSelection As Outlook.Selection
    Dim objMail As Outlook.MailItem
    Dim strFileName As String
    Dim objWordApp As Word.Application
    Dim objNewWordDocument As Word.Document
    Dim objWordRange As Word.Range
    Dim strWordDocument As String
    Dim i As Long
  
    'Create a temp folder
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp" & Format(Now, "YYYYMMDDhhmmss")
    MkDir (strTempFolder)
 
    On Error Resume Next
    'Save each selected email as an individual Word document in a temp folder
    Set objSelection = Outlook.Application.ActiveExplorer.Selection
    For Each objMail In objSelection
        strFileName = objMail.Subject
 
        'Remove the unsupported characters in email subject
        strFileName = Replace(strFileName, "/", " ")
        strFileName = Replace(strFileName, "\", " ")
        strFileName = Replace(strFileName, ":", "")
        strFileName = Replace(strFileName, "?", " ")
        strFileName = Replace(strFileName, Chr(34), " ")
 
        objMail.SaveAs strTempFolder & "\" & strFileName & ".doc", olDoc
    Next
 
    'Merge all the Word documents into a single document
    Set objWordApp = CreateObject("Word.Application")
    Set objNewWordDocument = objWordApp.Documents.Add
 
    strWordDocument = Dir(strTempFolder & "\" & "*.doc")
    i = 0
    Do Until strWordDocument = ""
       i = i + 1
       Set objWordRange = objNewWordDocument.Range
       With objWordRange
           .Collapse wdCollapseEnd
           If i > 1 Then
             .InsertBreak wdSectionBreakNextPage
             .End = objNewWordDocument.Range.End
             .Collapse wdCollapseEnd
           End If
           .InsertFile strTempFolder & "\" & strWordDocument
      End With
      strWordDocument = Dir()
    Loop
 
    'Change the path as per your own needs
    objNewWordDocument.SaveAs "E:\Exported Emails " & Format(Now, "YYYY-MM-DD hh-mm-ss")
    objWordApp.Quit
 
    'Delete the temp folder
    objFileSystem.DeleteFolder (strTempFolder)
End Sub

VBA Code - Batch Export Multiple Outlook Emails into One Word Document

  1. After that, you are better off adding this new VBA project to the Quick Access Toolbar or ribbon.
  2. Ultimately, you can take a try.
  • In the first place, select multiple Outlook emails.
  • Then locate and click on the newly added macro button.
  • After you are prompted of “Complete”, you can browse to the predefined local folder to find a new Word document.
  • Open this document, in which you can see all the selected emails have been exported.

Keep a Mighty Recovery Tool Nearby

Regardless of numerous functions, Outlook still cannot be immune from errors. If you’re used to leave errors alone, with them heaping up, Outlook crash will occur definitely. At that point, it is essential to recur to a mighty and effectual recovery tool, like DataNumen Outlook Repair. It is well versed in PST fix. As long as with it, you will not need to be concerned about outlook data loss any more.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted mdf and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.