Many users have the requirement of exporting multiple emails as a single PDF file in Outlook. Therefore, in this article, we’ll share you a piece of VBA code, which can accomplish this task in an instant.
Outlook doesn’t provide any features to export an Outlook email as a PDF file, not to mention exporting multiple emails as one PDF file. Hence, if you need to do it, you have to seek other approaches, such as third party tool or VBA. Thereinafter, we will expose a means which is using VBA code.
Export Multiple Outlook Emails as a Single PDF File
- First of all, you should launch your Outlook properly,
- Then, in the Outlook main screen, you could press “Alt + F11” keys to access its VBA editor.
- Next, in the “Microsoft Visual Basic for Applications” window, you could open a module that is not in use or simply insert a brand new module.
- Subsequently, you are required to copy the VBA code below into this module.
Sub ExportMultipleOutlookEmails_AsOnePDFFile() Dim objSelection As Outlook.Selection Dim objFileSystem As Object Dim strTempFolder As String Dim objMail As Outlook.MailItem Dim strFileName As String Dim strFilePath As String Dim objWordApp As Word.Application Dim objTempWordDocument As Word.Document Dim strFile As String Dim strPDF As String 'Get all selected emails Set objSelection = Outlook.Application.ActiveExplorer.Selection If Not (objSelection Is Nothing) Then 'Create a temp folder Set objFileSystem = CreateObject("Scripting.FileSystemObject") strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp" & Format(Now, "yyyymmddhhmmss") MkDir (strTempFolder) 'Save all emails as mht files in temp folder For Each objMail In objSelection strFileName = objMail.Subject strFileName = Replace(strFileName, "/", "-") strFileName = Replace(strFileName, "\", "-") strFileName = Replace(strFileName, ":", "-") strFileName = Replace(strFileName, "?", "-") strFileName = Replace(strFileName, Chr(34), "-") strFileName = Format(objMail.ReceivedTime, "yyyy-mm-dd") & " - " & strFileName & ".mht" strFilePath = strTempFolder & "\" & strFileName objMail.SaveAs strFilePath, olMHTML Next 'Create a temp Word document Set objWordApp = CreateObject("Word.Application") Set objTempWordDocument = objWordApp.Documents.Add 'Copy the contents of all mht files into the temp Word document strFile = Dir(strTempFolder & "\" & "*.mht") i = 0 While strFile <> "" i = i + 1 Set objWordRange = objTempWordDocument.Range With objWordRange .Collapse wdCollapseEnd If i > 1 Then .InsertBreak wdSectionBreakNextPage .End = objTempWordDocument.Range.End .Collapse wdCollapseEnd End If .InsertFile strTempFolder & "\" & strFile End With strFile = Dir() Wend 'Change the path to save the PDF file strPDF = "E:\Merged Emails.pdf" 'Export the temp Word document as a PDF file objTempWordDocument.ExportAsFixedFormat strPDF, wdExportFormatPDF 'Close & discard the temp Word document objTempWordDocument.Close False objWordApp.Quit 'Delete the temp folder objFileSystem.DeleteFolder (strTempFolder) MsgBox "Completed!" End If End Sub
- After that, you can exit the current window.
- Then go to “File” > “Options” > “Quick Access Toolbar” to add this new macro to Quick Access Toolbar.
- Later change your Outlook macro security level to low.
- Finally, just take a shot by following steps:
- Firstly, select multiple emails which you want to export.
- Then, click on the new macro button in Quick Access Toolbar.
- After you receive the message mentioning “Completed”, you can go to the predefined local folder to find the new PDF file.
- Open this PDF file. You’ll see that all the previously selected emails have been exported into separated pages.
Keep Tabs on Suspicious Risks around Outlook
Since Outlook is susceptible to corruptions for various factors, such as viruses, inner errors, software faults and hardware issues, etc., you should keep an eye on for a variety of potential dangerous matters around your Outlook. In addition, it is prudent to prepare a remarkable and dependable fix tool, such as DataNumen Outlook Repair. It is capable of performing successful Outlook recovery without any hassles.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair mdf and outlook repair software products. For more information visit www.datanumen.com