Backup Calendar, Contacts, Tasks in an IMAP data file

Last reviewed on April 11, 2014

Copied foldersOutlook 2013 allows users to set the IMAP data files as the default data file. As a result, appointments, contacts, tasks, and notes are stored in the IMAP data file. While many users like this because it means there is only one data file in the profile, it can result in data loss if you delete the account or the IMAP *.ost file and didn't export the folders labeled 'this computer only' first.

You should export these folders daily or weekly to create a backup copy, depending on how often they change. Note: backing up the IMAP .ost files is pointless - only the account and profile that created it can open it.

To make it easier to make a backup, you can use a macro to copy the Calendar, Contacts, Tasks, and Notes folders to a new .pst file.

This macro creates a new pst file in the My Documents\ Outlook Files folder, using a file name containing the date and time the backup was created, in the format of yyyymmddhhmmss-Backup.pst. The pst's display name is changed to Backup-yyyymmddhhmmss.

Backup pst files

If you need to restore the contents of the folders, you can Import, using this pst file as the source or Select All and Copy then use the Move to Folder command or Paste the items into the IMAP folders.

Macro to create backups

Note: this macro assumes only the default IMAP data file is in the profile.

Sub CreateBackupFiles()

Dim OlApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim copyToDataFile As Outlook.Folder
Dim copyFrom As Outlook.Folder
Dim myBackup As Outlook.Folder
Dim objFolder As Outlook.Folder
Dim folderType
Dim enviro As String, strDate As String 
Dim strFileName As String, pstName As String

Set objNS = Application.GetNamespace("MAPI")

enviro = CStr(Environ("USERPROFILE"))
strDate = Format(Date, "yyyymmdd") & Format(Time, "hhmmss")
strFileName = enviro & "\Documents\Outlook Files\" & strDate & "-BackUp" & ".pst"
pstName = "Backup " & strDate

Debug.Print strFileName

' Create the backup pst file
objNS.AddStore strFileName
Set objFolder = objNS.Folders.GetLast
objFolder.Name = pstName

Set copyToDataFile = Application.Session.Folders.Item(pstName)

For i = 1 To 4
Select Case i
    Case 1
     folderType = olFolderCalendar
    Case 2
     folderType = olFolderContacts
    Case 3
     folderType = olFolderTasks
    Case 4
     folderType = olFolderNotes
End Select

Set copyFrom = objNS.GetDefaultFolder(folderType)
Set myBackup = copyFrom.CopyTo(copyToDataFile)
 Next i
' remove the pst from the folder list
objNS.RemoveStore (objFolder)
Set objNS = Nothing
End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

5 responses to “Backup Calendar, Contacts, Tasks in an IMAP data file”

  1. Rich364

    Thanks Diane. This can help with some of my set ups - I haven't thought of using a macro for this before.

    Unfortunately I continue my never-ending search to find an auto-backup solution for the 5 Hosted Exchange and the 1 iCloud Account that I use in Outlook (no .pst accounts). I currently choose each account separately and do an export each week - time consuming and manual.

    Amazing how there's still no easy and automatic solution.

    Thanks again.

  2. Rich

    Yeah, that's good for disaster recovery situations. My concern is the incorrect deletion or change I may make to a contact, task or whatever. By having periodic backups I have the ability to try and correct a mistake.

  3. Rich364

    Ok... thank you :-)

Leave a Reply

If the Post Coment button disappears, press your Tab key.