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

Save email message as text file

Slipstick Systems

› Developer › Code Samples › Save email message as text file

Last reviewed on June 17, 2019     36 Comments

A visitor to OutlookForums saves messages as text files and was tired of changing the default Save as format to txt.

I save multiple messages everyday as text files. I just upgraded from 2007 outlook to 2010. Before the upgrade I had it defaulted to save as text. I did not do this that I recall it just has been that way. Now that I have upgraded it is defaulted to msg. Please tell me if there is a way to do this as it will save me an immense amount of excess clicking.

This macro is a manual version of E-Mail: Save new items immediately as files. Unlike the original macro, which saves all new messages as text file, you need to select a message and run this macro to save it as a text file.

For other options and utilities, see How to Save Email in Windows File System.

Save selected message as a text file

A version of this macro which saves all selected messages as multiple individual text files is at SaveSelectedMailAsTxtFile. The code sample at SaveSelectedMailBodiesTxtFiles is the modification discussed in this comment and reply.

Sub SaveMailAsFile()
 Const OLTXT = 0
 Dim oMail As Outlook.mailItem
 Dim sPath As String
  Dim dtDate As Date
  Dim sName As String

  Set oMail = Application.ActiveExplorer.Selection.Item(1)
  sName = oMail.Subject
  ReplaceCharsForFileName sName, "_"

  dtDate = oMail.ReceivedTime
  sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
    vbUseSystem) & Format(dtDate, "-hhnnss", _
    vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".txt"

  oMail.SaveAs "C:\path\to\save\" & sName, OLTXT
End Sub

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)
End Sub

 

Save selected messages to a single text file

This code sample saves the selected messages in one text file, replicating Outlook's behavior when you select multiple messages and choose Save as. It uses the current date and folder name as the file name and saves it to the user's My Documents folder.

Sub MergeSelectedEmailsIntoTextFile()

'From http://slipstick.me/fraz6
  
Dim objFS As New Scripting.FileSystemObject, objFile As Scripting.TextStream
Dim objItem As Object, strFile As String
Dim Folder As Folder
Dim sName As String

' Use your User folder as the initial path
Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))

  If ActiveExplorer.Selection.Count = 0 Then Exit Sub
  
' use the folder name in the filename
  Set Folder = Application.ActiveExplorer.CurrentFolder

' add the current date to the filename
sName = Format(Now(), "yyyy-mm-dd")

' The folder path you use needs to exist
strFile = enviro & "\Documents\" & sName & "-" & Folder & ".txt"
  
  Set objFile = objFS.CreateTextFile(strFile, False)
  If objFile Is Nothing Then
    MsgBox "Error creating file '" & strFile & "'.", vbOKOnly + vbExclamation _
      , "Invalid File"
    Exit Sub
  End If
  
  For Each objItem In ActiveExplorer.Selection
  
  With objFile
    .Write vbCrLf & "--Start--" & vbCrLf
    .Write "Sender: " & objItem.Sender & " <" & objItem.SenderEmailAddress & ">" & vbCrLf
    .Write "Recipients : " & objItem.To & vbCrLf
    .Write "Received: " & objItem.ReceivedTime & vbCrLf
    .Write "Subject: " & objItem.Subject & vbCrLf & vbCrLf
    .Write objItem.Body
    .Write vbCrLf & "--End--" & vbCrLf
 End With

  Next
  objFile.Close
  
  MsgBox "Email text extraction completed!", vbOKOnly + vbInformation, "DONE!"
  
  Set objFS = Nothing
  Set objFile = Nothing
  Set objItem = Nothing
  
End Sub

Replace the code between strFile = enviro... and objFile.close with the following. To add more fields, add more objFile.Write lines.

strFile = enviro & "\Documents\" & sName & "-" & Folder & ".txt"
Set objFile = objFS.OpenTextFile(strFile, ForAppending, True)
       For Each objItem In ActiveExplorer.Selection
        objFile.Write (objItem.Body)
      Next
        objFile.Close

 

Super short code

This code is super short and works on the currently open or selected message only. You'll need to GetCurrentItem function to use this macro. You'll need to add a check mark to the Microsoft Scripting Runtime in Tools, References.

Messages are appended to one file.

Public Sub SaveEmailBody()
Dim objMail As MailItem
    Dim fso As New FileSystemObject
    Dim ts As TextStream
    
' get the function athttp://slipstick.me/e8mio
    Set objMail = GetCurrentItem()
    Set ts = fso.OpenTextFile("E:\Documents\mailfile.txt", ForAppending, True)

    ts.Write (objMail.Body)
     ts.Close
    Set ts = Nothing
    Set fso = Nothing

End Sub

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 Outlook Email as a PDF
  • Save Selected Email Message as .msg File
  • Saving All Messages to the Hard Drive Using VBA
Save email message as text file was last modified: June 17th, 2019 by Diane Poremsky

Related Posts:

  • Save Messages as *.DOC or *.DOCX File Type
  • Save Selected Email Message as .msg File
  • Save Outlook Email as a PDF
  • Save all incoming messages to the hard drive

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
36 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Hubert (@guest_220089)
February 21, 2023 1:22 am
#220089

Dear Ms.Diane,

I use the script described above, but it stops working when a graphic appears in the email. I have already checked the Outlook settings and enabling the option:

<<Read all standard mail in plain text>>

does not help. The whole thing is converted to text, but the graphics stay as they were.

The error when executing the script appears in the line of code:

Write objItem.Body

and the error message is:

Run-time error '5':
Invalid procedure call or argument.

Is there a solution for this, or can the text content of the email be written to a text file despite the graphics that occur?

I kindly ask for support.

An example of a graphic that stops the script and causes an error.

?

Best regards.

Hubert

0
0
Reply
Kumaresan (@guest_213278)
May 18, 2019 4:30 am
#213278

Can anybody have a video for this task..If so please share it

1
0
Reply
Pat J (@guest_211401)
June 27, 2018 12:04 pm
#211401

Hi Diane,
Maybe I missed it but is there a setting I can set to allow me to default to .txt when saving a message as a file or possibly saving as last format used?

0
-1
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Pat J
June 28, 2018 1:06 am
#211407

You didn't miss anything - its not an option. Sorry.

1
0
Reply
Sarmistha (@guest_208603)
September 14, 2017 8:24 am
#208603

Hi Diane,
I am working on creating email from an Outlook template (.oft) file. The same has FomatText property as 'HTML'. The template is used to insert an image & necessary body (which includes tables; bullet points). I am facing issues with NewMessage.saveAs(path\filename&".msg", olMsg) statement. The issue is that it saves the filename.msg as plain 'TEXT'. The image is not visible and none of the formats i.e. bullets/table are visible. If I place NewMessage.display before/after 'saveAs' statement I can see the email generated as required i.e. with HTML content intact.

Can you please help me with suggestions as to what is going wrong in above line.

0
0
Reply
Meg (@guest_202691)
November 2, 2016 1:19 pm
#202691

Hi Diane, I have been using your code "Save selected message as a text file", but I want to save each email received and not the selected. you could help me? I understand this part define here "Set Omail = Application.ActiveExplorer.Selection.Item (1)" ?

0
0
Reply
Frank (@guest_199879)
July 8, 2016 10:24 am
#199879

First of all, thank you verry mutch. I have been using your code to save all mails in a selection as text file. I only have one problem that i can't solve. If i run the macro on Outlook 2010, there is no problem. But i still have one system that works with Outlook 2003 and for some reason, the macro stops after 50 messages, no mather what the selection is

0
0
Reply
Neha (@guest_199623)
June 27, 2016 5:57 am
#199623

Hi, I want to save all the mails from the same day with their date, is there a way to select mails with the current date in the vb script and then use those selected emails as above ?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Neha
July 6, 2016 10:57 am
#199829

I'm not sure what you want to do - the macro adds the received date to the saved file subject.

0
0
Reply
Mohan (@guest_195924)
January 12, 2016 4:09 pm
#195924

Hi Diane, thanks for the code, I'm using this code in outlook 2013 after building the rule from specific email address and using run script option. Only caveat is that I have to always select an email and run the rules to save that email to .txt file, is there a way that script can run automatically and save all the emails from that particular email address to .txt file. Thanks in advance for your reply.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 15

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
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • Remove a password from an Outlook *.pst File
  • Reset the New Outlook Profile
  • Maximum number of Exchange accounts in an Outlook profile
  • Save Attachments to the Hard Drive
  • How to Hide or Delete Outlook's Default Folders
  • 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
  • Classic Outlook is NOT Going Away in 2026
  • Use PowerShell to Delete Attachments
  • Remove RE:, FWD:, and Other Prefixes from Subject Line
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

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

Classic Outlook is NOT Going Away in 2026

Use PowerShell to Delete Attachments

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

Newest Code Samples

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

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

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.

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