/SaveOutlookEmails

Save and backup Outlook accounts and items (emails, appointments, attachments etc.) onto local drive.

Primary LanguageVBAApache License 2.0Apache-2.0

SaveOutlookEmails

Save and backup Outlook accounts and items (emails, appointments, attachments etc.) onto local drive.

PRs Welcome

Purpose

In my Outlook only the last three months of emails are available offline, the rest are archived and moved into my Online Archive - Name@Company.com account. Even when connected to the network the archived account only shows the first 200 odd characters of an email body and no attachments are available. This means that Outlook search won’t find anything from the archived account.

My solution to this problem is to save all emails from all accounts onto my desktop where I can perform search in Windows Explorer: search within emails body and in attachments.

Solution

SaveOutlookEmails saves accounts from Outlook onto a desktop folder. ProgressBar

  • Keep offline emails up-to-date date: autorun SaveOutlookEmails when Outlook starts (at start of Outlook Enable Macros when prompted with 'Microsoft Office has identified potential security concerns.')
  • Save archived accounts: run SaveOutlookEmails on selected folder (will take a while, run it at lunch time or at night, see more under Warnings)

Outlook's folder structure is kept the same and files are named with date-time prefix and shortened subject. Folder

Process

  • Outlook folders are validated against Invalid_Folders while Outlook items against Valid_Items.
  • Date and subject are checked whether the item has been saved before, if not then email validity checked in details.
  • When OLItem.MessageClass ends with any words defined in Archived_Array (in my case ends with 'EAS', my email archive client, if it is different in your cases update Archived_Array in Config) emails will be opened and then saved to get the full body and attachments.
  • Size and number of recipients are limited (see Config).
  • Outlook folder names and email subjects are cleaned for invalid characters.
  • Subject dynamically shortened to fit into full path limit (255 characters on Windows).
  • All successfully saved emails are added to Log.txt

Features

  • When auto run SaveOutlookEmails items on local drive are checked using fso.FileExists. When the number of already saved emails reaches Overlap_Resaved and the timeframe of already saved emails is over Overlap_Days then scanning emails will stop. Autorun won’t open emails as recent items are part of the offline Outlook database, including attachments.
  • When manually run on selected folders 'file exists' check is based on the Log file. This check is a simple loop though the log array. After an email has been found then the next loop will start from where the previous has been found to shorten the loop time.
  • Configuration file is saved at C:\Users\{Your-Name}\SaveOutlookEmails.txt where the backup location can be updated (e.g. C:\Users\{Your-Name}\OneDrive - {Company-Name}\eMails); default location C:\Users\{Your-Name}\Desktop\eMails.
  • It has been tested on Windows 7 and Windows 10, Outlook 2013 and Outlook 2016 versions.

Install

  1. Add Developer ribbon

Add Developer Ribbon

  1. Check Macro Settings in Trust Canter

Macro Settings

  1. Add Microsoft Scripting Runtime in VBA editor

Microsoft Scripting Runtime

  1. Copy code files from Code or SaveOutlookEmails Ver1.10.zip

Copy Code

Note: if your IT system blocks the use of bas files, then:

  • Download a copy of the AllInText Ver1.10.zip
  • Drag and drop BackBar.frm and BackupBar.frx
  • Copy the content of AllInText.txt
  • Create a new module: in VBA editor [Menu bar\ Insert\ Module]
  • Paste the code there
  1. Add auto run code to ThisOutlookSession

Auto Run

  1. Add Quick Access icon

Quick Access

  1. Hide Developer ribbon

Warnings

  • To save archived emails with full body and attachments, they must be opened and then saved. This will happen automatically causing the screen to flicker and limit the use of the computer.
  • If connection is slow or IT limits access, then SaveOutlookEmails will throw a run-time error: Click on 'End', restart Outlook and try to run SaveOutlookEmails again later.
  • I am dyslexic therefore spelling mistakes are likely within the code.
  • Not fully 'DRY', there is room for improvement.

Configuration

  • Maximum email size: Max_Item_Size = 25000000 25MB
  • Maximum number of recipients: Max_Item_To = 250
  • Invalid characters: * / \ : ? " % < > |, line feed, carriage return and horizontal tabulation
  • Overlap days: Overlap_Days = 7
  • Overlap number: Overlap_Resaved = 100
  • Overlap subject: Overlap_Subject = 20 is used to left-compare email subject and file name
  • Default folder on desktop: Defult_Folder = "Desktop\eMails"
Current version: 1.10