Export an email profile to PST

  • Thread starter Thread starter John L.
  • Start date Start date
J

John L.

We are using Microsoft Outlook in cached exchange mode. The email profiles
are using OST files.

Is there a way to export an email profile (email, contacts, tasks, schedules
etc.) using VBA code?

Thank you for the help.
 
You can copy the folders and items in the mailbox OST to a PST file, but
that won't include the profile information such as email accounts. Many
things in Outlook are stored in hidden items, which you won't be able to
copy in many cases, so things like global custom views probably won't make
it over.

Exactly what are you trying to accomplish? Have you considered looking for
commercial backup programs for Outlook?
 
Hi Ken,

Thank you for the info. We'd like to specifically obtain a backup of the
email (most importantly by far is the email in the inbox, deleted items, sent
items etc.) and calendar information if possible (tasks appointments etc.).
Is there a way to do this with VBA even though we are using Cached Exchange
Mode. We'd like to see a VBA code example that can run from a sub proc that
would export this.

We would rather not consider commercial solutions until we are sure that
this cannot be done with VBA. Auto Archive does not meet needs to make a
long story short. Thanks Ken.

John.
 
Well, Deleted Items holds trash, if your users keep items there that should
be retained they need some education in how to use Outlook.

Copying items to a PST file will change various properties on the items,
you'll have to accept that. It will also make backup more difficult since
each machine would need to be backed up as PST files are not supported for
storage on network shares or devices.

The basic idea would be to use the AddStore() method to add or create a new
PST file. Then you'd find the Inbox folder for both stores (creating it as
needed) and get each item in the folder and copy it to the new store. When
finished you can remove the store (PST file), although it will remain locked
by Outlook until Outlook is closed.

The code for Inbox would look something like this:

Sub BackupInbox()
Dim oBackup As Outlook.MAPIFolder
Dim oInbox As Outlook.MAPIFolder
Dim oBackInbox As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace
Dim colInboxItems As Outlook.Items
Dim colBackupInboxItems As Outlook.Items
Dim obj As Object 'Inbox items can be various types
Dim oCopy As Object

Set oNS = Application.GetNameSpace("MAPI")
Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
Set oBackup = oNS.AddStore("C:\Backup.PST") 'whatever path

Set oBackInbox = Nothing
Set oBackInbox = oBackup.Folders("Inbox")
If oBackInbox Is Nothing Then
Set oBackInbox = oBackup.Folders.Add("Inbox", olFolderInbox)
End If

Set colInboxItems = oInbox.Items
Set colBackupInboxItems = oBackInbox.Items

For Each obj In colInboxItems
' get the item type here and make the new item the same as the old
one.
' needs a long series of if then tests not shown here
' example shows just a mail item
Set oCopy = colBackupInboxItems.Add(olNoteItem)
Next
End Sub

That doesn't have error handling or releasing objects, but it shows the type
of code needed for what you want.
 
Back
Top