Backup Calendar, Contacts, Tasks in an IMAP data file

Last reviewed on September 17, 2014   —  5 comments

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.

Updated code: Macro now changes the backup folders to the correct item type.

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
Dim oPA As Outlook.PropertyAccessor
Dim PropName, Value As String

PropName = ""

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
     Value = "IPF.Appointment"

    Case 2
     folderType = olFolderContacts
     Value = "IPF.Contact"

    Case 3
     folderType = olFolderTasks
     Value = "IPF.Task"

    Case 4
     folderType = olFolderNotes
     Value = "IPF.StickyNote"

End Select
Set copyFrom = objNS.GetDefaultFolder(folderType)
Set myBackup = copyFrom.CopyTo(copyToDataFile)
Set oPA = myBackup.PropertyAccessor
oPA.SetProperty PropName, Value

 Next i
' remove the pst from the folder list
'objNS.RemoveStore (objFolder)
Set oPA = Nothing
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

About Diane Poremsky

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 Outlook forums by

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.

    1. Diane Poremsky

      I don't worry about backups of my hosted exchange or iCloud. If the Exchange server goes down, the account is synced on several computers and can be exported at that time. iCloud can be exported quickly just by signing out of iCloud and choosing the keep a copy option.

  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.

    1. Diane Poremsky

      if you are only worried about the special folders, you can use this macro to copy them to a pst file. It'll work with any account type - but is definitely more important for Outlook 2013 imap users since they are more at risk.

  3. Rich364

    Ok... thank you :-)

Leave a Reply

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

This site uses XenWord.