Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to automatically save Outlook emails to hard drive/disk?

For backup, work evidences, or other purposes, you may want to save Outlook emails to hard drive. It’s easy to save several emails to disk with manually dragging from Outlook to disk. However, do you know how to automatically save each incoming email to disk? This article will introduce a VBA to handle it in Outlook.

Automatically save Outlook emails to hard drive/disk

Kutools for Outlook: 100+ New Advanced Tools for Outlook.
Office Tab: Enable Tabbed Editing and Browsing in Office, Just Like Chrome, Firefox, IE 8/9/10.
Classic Menu: Bring Old Menus and Toolbars Back to Office 2007, 2010, 2013, 2016 and 2019.

Automatically save Outlook emails to hard drive/disk

This method will introduce a VBA to automatically save every incoming email in Outlook as individual HTML file to the specific disk. Please do as follows:

1. Press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Expand the Project1, and double click ThisOutlookSession to open it, and then paste below VBA code into the ThisOutlookSession window. See screenshot:

VBA: Automatically save Outlook emails as HTML files to disk

Private WithEvents InboxItems As Outlook.Items
Sub Application_Startup()
Dim xNameSpace As Outlook.NameSpace
Set xNameSpace = Outlook.Application.Session
Set InboxItems = xNameSpace.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub InboxItems_ItemAdd(ByVal objItem As Object)
Dim FSO
Dim xMailItem As Outlook.MailItem
Dim xFilePath As String
Dim xRegEx
Dim xFileName As String
On Error Resume Next
xFilePath = CreateObject("WScript.Shell").SpecialFolders(16)
xFilePath = xFilePath & "\MyEmails"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(xFilePath) = False Then
FSO.CreateFolder (xFilePath)
End If
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
If objItem.Class = olMail Then
Set xMailItem = objItem
xFileName = xRegEx.Replace(xMailItem.Subject, "")
xMailItem.SaveAs xFilePath & "\" & xFileName & ".html", olHTML
End If
Exit Sub
End Sub

3. Save the VBA code, and restart your Microsoft Outlook.

From now on, each incoming email will be saved as individual HTML file into the “MyEmails” folder.

Notes:
(1) This VBA will create a folder named “MyEmails” under the Documents folder. You can find out the automatically saved emails with this folder path: C:\Users\your_user_name\Documents\MyEmails
(2) This VBA will works with emails received in the Inbox folder of default email account.


Related Articles

 

Recommended Productivity Tools

shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121

Kutools for Outlook - More than 100 Advanced Functions for Outlook, Improve 70% Efficiency For you

  • Complicated and repeated operations can be done a one-time processing in seconds.
  • Forward multiple emails individually with one-click, and auto forward by rules.
  • Auto CC/BCC every sending email and easy for customizing rules, and auto reply without requiring exchange server.
  • Powerful junk emails filter, remove duplicate emails, reply with attachment, bunch of one-click operations, and so on...
  • 60-day unlimited free trial. 60-day money back guarantee. 2 years free upgrade and support. Buy once, use forever.
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Leslie · 3 months ago
    Could you advise how to change this to another folder, not the Inbox?
  • To post as a guest, your comment is unpublished.
    Olka · 4 months ago
    Dzień doby, robię wszystko tak jak opisane powyżej, mimo to makro nie chce działać. Czy muszę włączyć jakieś opcję albo zmienić coś w kodzie?
    Nie wywala błędu jednak nie tworzy się folder a plik się nie zapisuje.

    Będę bardzo wdzięczna za odpowiedź

    Pozdrawiam serdecznie
  • To post as a guest, your comment is unpublished.
    Matthias · 5 months ago
    How can I add the sender's email address to the file name?
  • To post as a guest, your comment is unpublished.
    Maxim · 5 months ago
    Buonasera, è possibile modificare questo script con una versione che prevede di spostare i messaggi che arrivano in altra cartella anzichè quella classica della posta in arrivo? In altri termini, vorrei salvare automaticamente le mail che arrivano per esempio in Posta in Arrivo\Cliente1
    grazie per la collaborazione
    max