Outlook Auto Archiving
When we get too many emails in Inbox @ work, it wastes our time in browsing through all mail items – 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 Outlook auto archiving.
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.
Old Mails to Archive Folder
To do this process, first create a PST folder specifically to store these backup emails. Then, Open you Outlook application & go to menu -> File -> Archiving (in Office Version 2007). This will open a Pop up menu asking you to choose these details.
- Select Folders from which the emails have to be archived.
- “Archive Items Older than’ – Choose a date here. So that Mail items older than this date will be moved to Outlook archive Folder.
- Choose a PST file, where the emails have to backup.
This completes the setup for Auto Archiving Outlook Emails. These might be slight variation in finding this option in the higher versions of Office application, but the steps are the same.
Move Mails to PST – Outlook Backup all Emails
By using this code, you can move every 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.
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.
Visual Basic1234567891011121314151617181920212223242526272829303132333435Sub Archive_Outlook_eMails_To_Backup_PST_Folder()' Declare ObjectsDim SourceFolder As Outlook.MAPIFolder, DestFolder As Outlook.MAPIFolderDim MailItem As Outlook.MailItemDim SourceMailBoxName As String, DestMailBoxName As StringDim Source_Pst_Folder_Name As String, Dest_Pst_Folder_Name As StringDim MailsCount As Double, NumberOfDays As Double'Set Number of days for aging checkNumberOfDays = 1'Source Mailbox or PST nameSourceMailBoxName = "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 nameDestMailBoxName = "Archive Folders"Dest_Pst_Folder_Name = "Inbox"Set DestFolder = Outlook.Session.Folders(DestMailBoxName).Folders(Dest_Pst_Folder_Name)MailsCount = SourceFolder.Items.CountWhile 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 ThenSourceFolder.Items.Item(MailsCount).Move DestFolderEnd IfMailsCount = MailsCount - 1WendMsgBox "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
Archive Email in Outlook – Macro to Move Email to PST