outlook-save-inbox-mail-items-to-the-file-system

Outlook - Save Inbox Mail Items To The File System

This macro saves all inbox mail items to the file system.

Outlook

  • 8253
  • 1819
  • 4
  • 0
Add to collection
© 2024VBAmacros.net

1 Open MS Outlook.


2 Go to Developer's tab > click on "Visual Basic" button or hit Alt + F11.


3 Go to Insert tab > click on "Module" or hit M.


4 Copy the VBA code from below.

5 Paste the code in the newly created module.


6 Go to Run tab > click on "Run Sub/UserForm" or hit F5.


7 That's it!


Advertisement

Code
'==========================================
' Save Inbox Mail Items To The File System
'==========================================
Sub saveInboxMailItemsToFileSystem()
    ' Set variables
    Dim ns As Outlook.NameSpace
    Dim inbox As Outlook.MAPIFolder
    Dim item As Outlook.MailItem
    Dim strFileName As String
    ' Set namespace
    Set ns = Application.GetNamespace("MAPI")
    ' Get inbox folder
    Set inbox = ns.GetDefaultFolder(olFolderInbox)
    ' Loop through all mail items
    For Each item In inbox.Items
        ' Set filename
        strFileName = "F:\VBAmacros\Outlook\" & item.Subject & " - " & VBA.Format(item.ReceivedTime, "yyyymmdd", vbUseSystemDayOfWeek) & ".msg"
        ' Save mail item to file system
        item.SaveAs strFileName, olSaveMsg
    Next item
End Sub
Advertisement


Comments
Sort by:
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
VBAmacros.net VBAmacros.net
Code was successfully copied!
VBAmacros.net VBAmacros.net
Please sign in!
VBAmacros.net VBAmacros.net
You've already voted!