Save Messages as *.DOC File Type

Last reviewed on November 1, 2014   —  9 comments

An Outlook user wanted to save all of his messages to his hard drive in *.doc format, so that the messages would be in a universal format and the attachments would stay with the document. While you can do this in Outlook, it takes several steps: you need to open the message, go into Edit mode, change the message format to Rich Text (RTF) and save it. Then use SaveAs to save the message to the hard drive.

Using VBA speeds the process up quite a bit.

To save attachments to your hard drive then open them: Save and Open an Attachment using VBA. To save attachments and remove them from the message, see Save and Delete Attachments from Outlook messages

The code adds the message date and time stamp to the filename, to avoid problems if multiple messages have the same subject. You could also add the sender's name to the filename, if desired. The date and time stamp code was taken from E-Mail: Save new items immediately as files.

Save as Doc Macro

If the folder you want to save the documents to does not exist, create it before running the macro.

To use this code, open the VBA editor using Alt+F11 and paste this code into ThisOutlookSession. Change the path where the documents will be saved. Select a folder and run the macro. All messages within the folder will be saved as a Word document file.


Sub SaveAsDoc()

Dim myolApp As Outlook.Application
Dim aItem As Object

Dim dtDate As Date
Dim sName As String

Set myolApp = CreateObject("Outlook.Application")
Set mail = myolApp.ActiveExplorer.CurrentFolder


For Each aItem In mail.Items
    aItem.BodyFormat = olFormatRichText

'If you want to convert all messages to RTF, uncomment this line. 
'Otherwise, the message format is not changed. 
   ' aItem.Save


sName = aItem.Subject
ReplaceCharsForFileName sName, "_"


dtDate = aItem.ReceivedTime
  sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
    vbUseSystem) & Format(dtDate, "hhnnss", _
    vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName
    
    
aItem.SaveAs "C:\email\" & sName & ".doc", olRTF

Next aItem

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

Use an ItemAdd Macro to Save as .Doc

This version of the macro is saves messages as doc files as they are dropped in a folder, either by rules or by dragging the message to the folder. As written, it watches a folder under the Inbox.

Add the ReplaceCharsForFileName sub (from the macro above) at the end of this macro.

Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objItems As Outlook.Items

Private Sub Application_Startup()
Dim objFolder As Outlook.folder
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
Set objItems = objFolder.Folders("Folder01").Items
Set objFolder = Nothing
End Sub

Private Sub objItems_ItemAdd(ByVal aItem As Object)
 
Dim dtDate As Date
Dim sName As String
 
aItem.BodyFormat = olFormatRichText
 
'If you want to convert all messages to RTF, uncomment this line.
'Otherwise, the message format is not changed.
   ' aItem.Save
 
sName = aItem.Subject
ReplaceCharsForFileName sName, "_"
 
 
dtDate = aItem.ReceivedTime
  sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
    vbUseSystem) & Format(dtDate, "hhnnss", _
    vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName
      
aItem.SaveAs "C:\email\" & sName & ".doc", olRTF
 
End Sub

' put the ReplaceCharsForFileName sub here

Written by

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.

Please post long or more complicated questions at Outlookforums.

9 responses to “Save Messages as *.DOC File Type”

  1. Sus Boyce

    Bless your heart - thank you very much. this is precisely what I was look for. Thank you for saving me tons of time.

  2. A

    This is great, but is there a way to delete all attachments from the message before they are saved, therefore creating just the email text as a Word doc? Obviously this can be commented out like the convert to RTF line.

  3. Dwight Huse

    Diane,
    I had a terrible time getting this to work for me. I kept getting a VBA message box stating, Compile Error: Sub or Function not defined. I struggled for a long time until I realized that I must have captured some stray hidden characters when I copied your code. Once I cleaned up all those hidden characters, your code works great. I was dismayed that a dozen coding sites trying to answer this same VBA error message for others have not been able to identify a simple problem like this.

    Thank you so very much for sharing your code.
    -Dwight

  4. Pete Constantine

    Diane,

    Thanks for the awesome code!! It works exactly as described and flawlessly. In looking at the code, I am trying to determine if I can apply this to a specific folder; not just the current folder. I imagine it is associated with this particular line :

    "Set mail = myolApp.ActiveExplorer.CurrentFolder"

    However, my very limited knowledge of VBA inhibits my ability to figure it out. Do you have any pointers?

    Thanks again for this.

  5. Jennifer McDonald

    Hi Diane, you have posted several create codes; however my limited knowledge of VBA is contributing to my errors. I am trying to create a code that will save emails as Word Documents on my hard drive. I am moving the appropriate items to a folder in my inbox named: @SaveAsDoc and I have a folder on my hard drive saved at this path: C:\Documents and Settings\jennifer.mcdonald\2SaveAsDocOutlookMessages .

    I have tried cutting and pasting the code and renaming the folders, but I think my process is a little more involved since I am already moving the items to a subfolder of the inbox. I found some information that left me to believe I may need to use this: Items.ItemAdd Event . I continue to get an error highlighting "Dim" that states Complie Error: Expected End of Statement. Can you possibly help me?

    Thanks,
    Jennifer

Leave a Reply

If the Post Coment button disappears, press your Tab key.