• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Backup Calendar, Contacts, Tasks in an IMAP data file

Slipstick Systems

› Developer › Backup Calendar, Contacts, Tasks in an IMAP data file

Last reviewed on September 8, 2020     14 Comments

Applies to: Outlook (classic)

Copied foldersBeginning with Outlook 2013, Outlook 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 open the pst in the profile then 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 = "http://schemas.microsoft.com/mapi/proptag/0x3613001E"

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 = objFolder
 
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

Backup Calendar, Contacts, Tasks in an IMAP data file was last modified: September 8th, 2020 by Diane Poremsky

Related Posts:

  • How to move IMAP data files
  • Using IMAP Accounts in Outlook
  • Pick Contacts using VBA
  • Move Appointments to an Archive Calendar

About 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.

Subscribe
Notify of
14 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

B. Fulwiler
September 13, 2021 7:37 pm

Thank you very much for this post. It is most helpful. However, as is, it keeps the backup file associated with the profile and displayed in the folders list.
the "objNS = Nothing" line is commented out. Remove the Comment (') and the macro removes the data file, and it is no longer displayed in the Folders list.
I think the last few lines should be:
=============================
' remove the pst from the folder list
objNS.RemoveStore objFolder

Set oPA = Nothing
Set objNS = Nothing
End Sub
=============================

0
0
Reply
JPR_
July 7, 2020 9:11 am

Hello Diane,
I've been running your macro for more than 2 years but now Outlook is throwing an error message: "Run-time error '13': Type mismatch".
Do you know why? I am not very sure if its because a Windows update (OS) or an Office update tho.

I have recreated the certificate, removed the security settings in order to run all types of macros and still nothing.
Not sure if I can share links in here but I also posted a question in Outlook's community forum: https-->answers.microsoft.com/en-us/outlook_com/forum/all/unable-to-run-a-macro/47fae841-f220-45ae-808f-97056a35e934

Hope to hear from you soon,

Cheers!

0
0
Reply
JPR_
March 9, 2018 7:15 pm

Wow great post Diane!
I love this macro!

I tweaked a little bit (I do not need notes and other small stuff) but I have a question:
Is it possible to create the backup without seeing the outlook file (data-file)?

0
0
Reply
Diane Poremsky
Author
Reply to  JPR_
March 9, 2018 11:20 pm

No, not using the macro. The data file needs to be in outlook and outlook needs to be open.

0
0
Reply
David Jonathan
March 11, 2015 12:36 pm

Yes, I looked in the Recover deleted folder.
AND Yes, OST files are not usable, and their contents still are in need of a local, restorable backup for when Microsoft can't explain why the Inbox disappeared and the contents did not go into a deleted files folder.

0
0
Reply
David Jonathan
March 10, 2015 1:37 pm

Thanks for the reply, and, that is the same story that three Microsoft support technicians shared with us. However, that is NOT what happened. Microsoft was wrong. Searching online, I find many other folks have had the same email disappearance occur. The MS Office 365 Support were quick to admit that there could be a possible problem with the Outlook 2013 software, but that would be the MS Office software division's problem (and they don't talk to those folks). Friday January 2nd my wife and I were both at home, and mostly not working. Her home office computer is her primary workplace, she rarely uses any other device to check email, and had no need to use another device since she was at home. If the chance ever arises for her to need email set up on any device, that is my job, as I am her primary tech support, (I do IT support for small business for a living). I would avoid using pop3 (in favor of imap, or MS Exchange sync) on any device, especially on a little used, secondary device. At 11a.m. she checked her email on her primary office computer using Outlook 2013 (the program), then… Read more »

0
0
Reply
Diane Poremsky
Author
Reply to  David Jonathan
March 11, 2015 1:25 am

OST files aren't usable in other profiles - they belong to the profile that created the ost. You can export the contents to a pst - it's certainly not as fast as just copying the pst, but in the case of imap, insures you have the full message body.

Did you look in the Recover deleted folder?

0
0
Reply
David Jonathan
February 17, 2015 8:09 pm

Jan 2nd, 2015. Inbox contents disappeared.
My wife has an Exchange Online (office 365) paid email account for her business use. On Jan. 2nd, she checked her email in the morning, at her home office. While she was at lunch, the contents of her Inbox disappeared. 3500 emails gone (not a great practice, but many folks like outlook because they can "see" all their email in one place). The email did not go into the deleted items folder. However the disappearance of the inbox contents was synced to her other computer at her office pc. When we look at her iphone, we could see here inbox contents for a few seconds before the MS Exchange sync kiked in and replicated nothingness to her iPhone email client also.
Turns out Microsoft does not have a backup system (unless you pay for Legal Hold), just a replication system.

So, it might be helpful to recommend a good back up tool for backing up Cloud based data sets (email, Contacts & Calendar ) that can be pulled from an Outlook 2013 client. I know I would dearly like to have one that worked.

0
0
Reply
Diane Poremsky
Author
Reply to  David Jonathan
March 10, 2015 12:16 am

The only reason the mail should disappear from the server is if she opened the mailbox on another computer and set it up as pop3 and deleted it from the server as it was downloaded.

All mail that is deleted goes into Deleted items recovery - so it should be recoverable even if it's not in the deleted items folder.

0
0
Reply
Rich364
April 4, 2014 4:59 pm

Ok... thank you :-)

0
0
Reply
Rich
April 4, 2014 4:09 pm

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.

0
0
Reply
Diane Poremsky
Reply to  Rich
April 4, 2014 4:56 pm

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.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 33

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Reset the New Outlook Profile
  • Use PowerShell to get a list of Distribution Group members
  • Shared Mailboxes and the Default 'Send From' Account
  • Office Outlook Add-ins
  • Automatically BCC All Messages
  • Gmail All Mail and Outlook’s Archive folder
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment