• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Save Outlook Email as a PDF

Slipstick Systems

› Developer › Code Samples › Save Outlook Email as a PDF

Last reviewed on August 29, 2018     163 Comments

A security update disabled the Run a script option in the rules wizard in Outlook 2010 and all newer Outlook versions. See Run-a-Script Rules Missing in Outlook for more information and the registry key to fix restore it.

There are two ways to save Outlook messages in PDF format: by printing to a PDF printer or saving in PDF format from Word. This sample shows how to use the Word Object Model to save as PDF. (There is a third way: use Adobe Acrobat's package feature. It makes a really nice PDF archive, if you own Acrobat.)

This code sample will save one or more selected Outlook email messages as a PDF file. Because it uses Word object to save, this code could easily be tweaked to save messages in any format Word can save as.

Don't forget to set a reference to the Word object library in Tools > References. Select the correct version for your version of Office. (Most people will only have one entry, the correct one.)
Set the VB references

A version of this macro to use in a run a script rule is here.

Sub SaveMessageAsPDF()
     
    Dim Selection As Selection
    Dim obj As Object
    Dim Item As MailItem
     
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Set wrdApp = CreateObject("Word.Application")
    Set Selection = Application.ActiveExplorer.Selection

For Each obj In Selection
 
    Set Item = obj
    
    Dim FSO As Object, TmpFolder As Object
    Dim sName As String
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set tmpFileName = FSO.GetSpecialFolder(2)
    
    sName = Item.Subject
    ReplaceCharsForFileName sName, "-"
    tmpFileName = tmpFileName & "\" & sName & ".mht"
    
    Item.SaveAs tmpFileName, olMHTML
    
    
Set wrdDoc = wrdApp.Documents.Open(FileName:=tmpFileName, Visible:=True)
  
    Dim WshShell As Object
    Dim SpecialPath As String
    Dim strToSaveAs As String
    Set WshShell = CreateObject("WScript.Shell")
    MyDocs = WshShell.SpecialFolders(16)
       
strToSaveAs = MyDocs & "\" & sName & ".pdf"
 
' check for duplicate filenames
' if matched, add the current time to the file name
If FSO.FileExists(strToSaveAs) Then
   sName = sName & Format(Now, "hhmmss")
   strToSaveAs = MyDocs & "\" & sName & ".pdf"
End If
  
wrdApp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    strToSaveAs, ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
    Range:=wdExportAllDocument, From:=0, To:=0, Item:= _
    wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False
             
Next obj
    wrdDoc.Close
    wrdApp.Quit
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    Set WshShell = Nothing
    Set obj = Nothing
    Set Selection = Nothing
    Set Item = Nothing
 
End Sub
 
' This function removes invalid and other characters from file names
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
  sName = Replace(sName, "/", sChr)
  sName = Replace(sName, "\", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "?", sChr)
  sName = Replace(sName, Chr(34), sChr)
  sName = Replace(sName, "<", sChr)
  sName = Replace(sName, ">", sChr)
  sName = Replace(sName, "|", sChr)
  sName = Replace(sName, "&", sChr)
  sName = Replace(sName, "%", sChr)
  sName = Replace(sName, "*", sChr)
  sName = Replace(sName, " ", sChr)
  sName = Replace(sName, "{", sChr)
  sName = Replace(sName, "[", sChr)
  sName = Replace(sName, "]", sChr)
  sName = Replace(sName, "}", sChr)
  sName = Replace(sName, "!", sChr)
End Sub

Save without the Headers

This version of the macro saves the message without the short To/From/subject headers normally found at the top of a printed message.

message header

Sub SaveMessageAsPDF()
     
'Set up the browser
    Dim browser As String
    Dim ConvertMail As Boolean
    Dim CheckHTML As Boolean
    browser = "C:\Program Files\Internet Explorer\iexplore.exe"
    ConvertMail = False
    CheckHTML = True
     
    Dim Selection As Selection
    Dim obj As Object
    Dim Item As MailItem
     
 
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Set wrdApp = CreateObject("Word.Application")
    Set Selection = Application.ActiveExplorer.Selection

For Each obj In Selection
 
    Set Item = obj
    
    Dim FSO As Object, TmpFolder As Object
    Dim sName As String
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set tmpFileName = FSO.GetSpecialFolder(2)
    
    sName = Item.Subject
    ReplaceCharsForFileName sName, "-"
    tmpFileName = tmpFileName & "\" & sName & ".htm"
    

 Dim ConvertHTML As Boolean
    ConvertHTML = True

    If Item.BodyFormat = olFormatHTML And ConvertMail = False Then
        Dim rawHTML As String
        rawHTML = Item.HTMLBody

        If CheckHTML = False Then
            ConvertHTML = False
        Else
            If InStr(UCase(rawHTML), UCase("src=""cid:")) = 0 Then
                ConvertHTML = False
            End If
        End If
    End If
     If ConvertHTML = False Then
            Set objFile = FSO.CreateTextFile(tmpFileName, True)
            objFile.Write "" & rawHTML
            objFile.Close
            Set objFile = Nothing
    Else
            Item.SaveAs tmpFileName, olHTML
    End If
   
Set wrdDoc = wrdApp.Documents.Open(FileName:=tmpFileName, Visible:=True)
  
    Dim WshShell As Object
    Dim SpecialPath As String
    Dim strToSaveAs As String
    Set WshShell = CreateObject("WScript.Shell")
    MyDocs = WshShell.SpecialFolders(16)
       
strToSaveAs = MyDocs & "\" & sName & ".pdf"
 
' check for duplicate filenames
' if matched, add the current time to the file name
If FSO.FileExists(strToSaveAs) Then
   sName = sName & Format(Now, "hhmmss")
   strToSaveAs = MyDocs & "\" & sName & ".pdf"
End If
  
wrdApp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    strToSaveAs, ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
    Range:=wdExportAllDocument, From:=0, To:=0, Item:= _
    wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False
             
Next obj
    wrdDoc.Close
    wrdApp.Quit
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    Set WshShell = Nothing
    Set obj = Nothing
    Set Selection = Nothing
    Set Item = Nothing
 
End Sub
 
' This function removes invalid and other characters from file names
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
  sName = Replace(sName, "/", sChr)
  sName = Replace(sName, "\", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "?", sChr)
  sName = Replace(sName, Chr(34), sChr)
  sName = Replace(sName, "<", sChr)
  sName = Replace(sName, ">", sChr)
  sName = Replace(sName, "|", sChr)
  sName = Replace(sName, "&", sChr)
  sName = Replace(sName, "%", sChr)
  sName = Replace(sName, "*", sChr)
  sName = Replace(sName, " ", sChr)
  sName = Replace(sName, "{", sChr)
  sName = Replace(sName, "[", sChr)
  sName = Replace(sName, "]", sChr)
  sName = Replace(sName, "}", sChr)
  sName = Replace(sName, "!", sChr)
End Sub

Save as a DOCX File

To save the message as a Word Document using the DOCX file type, replace the code blocks that saves as a pdf with the code below.

wrdApp.ActiveDocument.SaveAs2 FileName:= _
        strToSaveAs, FileFormat:=wdFormatXMLDocument, LockComments:=False, Password:="", _
        AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
        :=False, SaveAsAOCELetter:=False, CompatibilityMode:=15

 

How to Use Macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 and above, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

  • How to Save Email in Windows File System
  • Import Messages from File System into Outlook Folders
  • OWA: Save Messages to My Documents
  • Save a Message as HTML and Delete the (Annoying) Folder
  • Save email message as text file
  • Save Outlook Email as a PDF
  • Save Selected Email Message as .msg File
  • Saving All Messages to the Hard Drive Using VBA

Print Email (and Attachments) on Arrival has a list of utilities that can print messages and attachments.

Save Outlook Email as a PDF was last modified: August 29th, 2018 by Diane Poremsky

Related Posts:

  • Save Messages as *.DOC or *.DOCX File Type
  • Save all incoming messages to the hard drive
  • Save email message as text file
  • Save Selected Email Message as .msg File

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
163 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Pedro
March 13, 2023 10:50 am

Hi Diane,

is it possible to prompt for the file location on a save as dialog?
Thanks

0
0
Reply
Diane Poremsky
Author
Reply to  Pedro
March 13, 2023 10:22 pm

You can use the browse for folder option in this article - https://www.slipstick.com/developer/code-samples/windows-filepaths-macro/

0
0
Reply
Pedro
Reply to  Diane Poremsky
March 14, 2023 5:51 am

Hi Diane,
i don't know what to change in the code to include BrowseForFolderCan you help?
Thanks

0
0
Reply
Pedro
Reply to  Diane Poremsky
March 15, 2023 10:06 am

Hi Diane,
i don't know what part of the code to modify.
Can you help please?

0
0
Reply
Kennan Bieniawski
October 6, 2022 10:33 am

I have code similar to this shown below. However I am having trouble as when saving emails that have photos they are often cut-off. I can't seem to find a way to get the photos to either shrink to fit the dimensions or some other method.

0
0
Reply
James Martin
Reply to  Kennan Bieniawski
April 27, 2023 6:43 am

Hi Kennan,

See the txt file of my bas file for my Macro Es. I use upper or lowercase initials for my Macros. Macro E is to save the email Header and body to Word.

Towards the end of the macro you will see Macro s , to force high res embedded images to within the page margin.

I have not cleaned out noted out code, as I have not resolved if Macro Es is run with Word App not open - I have to end task for the Word entry lower down in Task Manager, if run with Word App closed.

The way I have saved the email details for the file name should be of interest. A lot of trial and error.

There is some recent code added to flash up a MsgBox, for Macro L, in Excel which logs all my active windows, and productivity data, this is posted on my LinkedIn page.

OutlookMacroEands 22 02 2023.txt
0
0
Reply
James Martin
Reply to  Kennan Bieniawski
April 27, 2023 7:24 am

In addition to my previous comment, I also have amended versions of the Slipstick save attachments to a folder "save-attachments-to-the-hard-drive". Macro A. And the Slipstick macro for saving a txt version of an email, if needed. I call this Macro e "save-email-message-text-file". These 3 macros including Macro Es were critical to I'mproving productivity. There is a 4th Macro in Word to import image files downloaded from the Macro A to a temp folder you specify, and Import them at the cursor point. This saves a lot of time for an archiving role I have been doing. For pdfs I have not created a macro to control the pages if under 11 pages (we have a 4MB file upload limit), and import these at the cursor point. I am manually rotating pdfs to landscape, full screening, and pasting into the docx. I have Macro R to rotate all or selected images. (via Grey Maxey). I also have Macro C/c to compress images by 150/96ppi. Macro B for page/section Break, and Header and Footer unlink - is from Greg Maxey. Macro S is to maximise images, as they shrink when moved in the document. Macro T is to force tables mainly in… Read more »

WordMacroX 22 02 2023.txt
WordMacroI 22 02 2023.txt
0
0
Reply
James Martin
September 24, 2021 8:07 am

I have got the pdf Outlook Item Macro to work, with change to docx with Header, as this file type is better for editing the order of embedded customer photos of documents. I need some code when the objects/items from outlook are moved to Word, before the saving. Basically customers upload images of document pages from mobiles, and the images are embedded in the email body and not classed as attachments. Most photos are oversized in the docx produced. I currently forward selected email and copy the Forwarded email body and paste H into docx and this naturally wraps all images within the margins even if in landscape. [I have a rotation macro to correct selected or all images by 90, 180 or 270 degrees, I received help from http://www.gregmaxey.com to get the two listboxes to work in a UserForm for the select or all rotation macros.] I have noticed cutting the images in the docx from the run macro and repasting with paste K, resolves the wrapping problem, but I am struggling to code this. The other problem with my manual method is that the attachments list is not included in the forwarded email body and the most recent… Read more »

0
0
Reply
Philip Coltharp
June 14, 2021 2:14 pm

Thank you Diane, thank you, thank you, thank you, thank you, thank you ...

0
0
Reply
Matt Lane
July 5, 2020 1:56 pm

Hey Diane, Thank you for posting. Love how the code includes the headers. Having a bit of trouble. When i select items from my inbox, it saves them to the specified desktop folder. When i try to select emails from a sub folder of my outlook inbox, I run into an error "Outlook cannot save this file because it is already open elsewhere." on the following line of code: Item.SaveAs tmpFileName, olMHTML. I like saving the emails to a subfolder as i need to save them for an access review. I have an outlook rule moving ~1000 of them to the subfolder so i can group them. Any ideas? Thanks!

0
0
Reply
Tapas
June 25, 2020 4:51 am

Hi Diane,
I have an email that has a table (or a picture) in it that gets cropped when i use this macro to save as pdf. Any suggestions to fit all data to a page in the pdf?
 

0
0
Reply
Javier
May 25, 2020 11:08 pm

Hello Diane. When I have selected a confirmation (example: Accepted: invitation ...) this won't work and throw an error in here:

For Each obj In Selection
     Set Item = obj

The error message is:

Run-time error '13': Type missmatch

I guess confirmations are a different object.

Do you know how I can fix it? I want to gather information from aa bunch of meeting confirmations.

Thanks in advance.

0
0
Reply
Neelesh
December 1, 2019 12:28 am

I get a debug error at Set objFile = FSO.CreateTextFile(tmpFileName, True) Sub SaveMessageAsPDF() 'Set up the browser Dim browser As String Dim ConvertMail As Boolean Dim CheckHTML As Boolean browser = "C:\Program Files\Internet Explorer\iexplore.exe" ConvertMail = False CheckHTML = True Dim Selection As Selection Dim obj As Object Dim Item As MailItem Dim wrdApp As Word.Application Dim wrdDoc As Word.Document Set wrdApp = CreateObject("Word.Application") Set Selection = Application.ActiveExplorer.Selection For Each obj In Selection Set Item = obj Dim FSO As Object, TmpFolder As Object Dim sName As String Set FSO = CreateObject("Scripting.FileSystemObject") Set tmpFileName = FSO.GetSpecialFolder(2) sName = Item.Subject ReplaceCharsForFileName sName, "-" tmpFileName = tmpFileName &amp; Format(Now, "yyyy-mm-dd", vbUseSystemDayOfWeek, vbUseSystem) &amp; sName &amp; ".htm" Dim ConvertHTML As Boolean ConvertHTML = True If Item.BodyFormat = olFormatHTML And ConvertMail = False Then Dim rawHTML As String rawHTML = Item.HTMLBody If CheckHTML = False Then ConvertHTML = False Else If InStr(UCase(rawHTML), UCase("src=""cid:")) = 0 Then ConvertHTML = False End If End If End If If ConvertHTML = False Then Set objFile = FSO.CreateTextFile(tmpFileName, True) objFile.Write "" &amp; rawHTML objFile.Close Set objFile = Nothing Else Item.SaveAs tmpFileName, olHTML End If Set wrdDoc = wrdApp.Documents.Open(FILENAME:=tmpFileName, Visible:=True) Dim WshShell As Object Dim SpecialPath As String Dim… Read more »

0
0
Reply
Diane Poremsky
Author
Reply to  Neelesh
December 2, 2019 12:44 pm

Does it give you an error message or just stop at that line? What do you have set for the filepath?
tmpFileName = tmpFileName & Format(Now, "yyyy-mm-dd", vbUseSystemDayOfWeek, vbUseSystem) & sName & ".htm"

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 29

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment