Auto Outlook Archive Email
What does it mean to archive an email? When we get too many emails in Inbox @ work, it wastes our time in browsing through all mail items.
We spend too much effort in cautiously picking important items & keeping aside unwanted items. Not only our productive time and effort get wasted, but also Outlook application’s performance goes down. So, it is always good to backup mails periodically to a different PST by setting up Auto Outlook archive Email.
This article explains 2 methods of archiving Outlook emails. First through the built in option by creating a Outlook Archive Folder and the second through a VBA Macro code to move Emails in your inbox to PST, when they become older than a predefined time interval.
How To Archive Email in Outlook?
To do this process, first create a PST folder specifically to store these backup emails. Then follow these steps.
- Open you Outlook application.
- Click on Menu -> File -> Archiving (in Office Version 2007).
- Select Email Folder to be archived.
- Choose date for “Archive Items Older than’ field.
- Choose archival PST file, where the emails have to backup.
This completes the setup for Auto Outlook Archive Email. The eMail items older than the date specified in Steps 4 – will be moved to Outlook archive Folder.
These steps might be slightly different in the higher versions of Office application, but the steps are the same.
Export eMails To PST – Outlook Backup all Emails
Now, let’s focus on how to move an email items to a PST folder & Archive emails in Outlook through VBA. Open the Outlook application and press “Alt+F11”. This will open the VB Editor.
- Copy paste the below code.
- Change source & destination Mailbox and Folder name.
- In this code, the mails older than 100 days will be moved to PST. Modify it as per your need.
Note: Before testing this code, keep a copy of your PST in separate folder to prevent accidental data loss.
Sub Archive_Outlook_eMails_To_Backup_PST_Folder() ' Declare Objects for Outlook Archive Email Dim SourceFolder As Outlook.MAPIFolder, DestFolder As Outlook.MAPIFolder Dim MailItem As Outlook.MailItem Dim SourceMailBoxName As String, DestMailBoxName As String Dim Source_Pst_Folder_Name As String, Dest_Pst_Folder_Name As String Dim MailsCount As Double, NumberOfDays As Double 'Set Number of days for aging check NumberOfDays = 1 'Source Mailbox or PST name SourceMailBoxName = "YourEmailAccount@gmail.com" Source_Pst_Folder_Name = "SourcePSTFolder" Set SourceFolder = Outlook.Session.Folders(SourceMailBoxName).Folders(Source_Pst_Folder_Name) 'Backup to this Mailbox or PST name DestMailBoxName = "Archive Folders" Dest_Pst_Folder_Name = "Inbox" Set DestFolder = Outlook.Session.Folders(DestMailBoxName).Folders(Dest_Pst_Folder_Name) MailsCount = SourceFolder.Items.Count While MailsCount > 0 'Backup Mails Older than "Number of Days" Set MailItem = SourceFolder.Items.Item(MailsCount) If VBA.DateValue(VBA.Now) - VBA.DateValue(MailItem.ReceivedTime) >= NumberOfDays Then SourceFolder.Items.Item(MailsCount).Move DestFolder End If MailsCount = MailsCount - 1 Wend MsgBox "Mailes in " & Source_Pst_Folder_Name & " are Processed" End Sub
To execute this code, press “F5” or if you want to debug the code line by line press F8. Also make sure that the Mailbox & Folder names are mentioned correctly before executing the code.
Also Read: Send Automated Emails through VBA Macro
By using this code, you can archive Outlook mail items to 1 or more back up PST file. This way, when any data is accidentally lost, then we have additional place to look for. These days cloud storage systems are gaining popularity, where people keep an offsite backup of data and emails, so that data can be recovered even when whole system goes down.