Export Folder to PST

KevinE

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Looking for a code snippet to export a selected folder to PST.

I have literally hundreds of email folders for each project I work on. My account is almost at the O365 50GB limit and to I need to start archiving these folders. I can't seem to find any API functions to export to PST.
 

Dan_W

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
Hi

This should do what you need. Note that the code will move all the items in the folder to the new PST file, so you should do a few practice runs with a folder of dummy emails, etc. to make sure it works first. Also, you will need to make adjustments to the file path and the filename, etc. As it is, it currently sources part of the filename from the folder name.

Rich (BB code):
Sub ArchiveEmailPST()
Dim olNS As outlook.NameSpace
Dim olBackup As outlook.folder
Dim olSourceFolder As outlook.folder
Dim olSourceItem As Object
Dim strPath As String
Dim strDisplayName As String

Set olNS = GetNamespace("MAPI")
Set olSourceFolder = olNS.PickFolder
strDisplayName = olSourceFolder.name & "-Archive_" & Format(date, "yyyymmdd-hhmmss")
strPath = "C:\TEMP\" & strDisplayName & ".pst"

'Creates a PST file at the path (strPath).
olNS.AddStore strPath
Set olArchive = olNS.Folders.GetLast
olArchive.name = strDisplayName

'Moves across all the items in the selected folder to the PST
For counter = olSourceFolder.Items.Count To 1 Step -1
    Set olSourceItem = olSourceFolder.Items(counter)
    olSourceItem.Move olArchive
Next

'Closes and removes the PST file
olNS.RemoveStore olArchive

Set olNS = Nothing
Set olSourceFolder = Nothing
Set olArchive = Nothing
Set olSourceItem = Nothing
End Sub
 

jessewalter375

Senior Member
Outlook version
Outlook 2019 64-bit
Email Account
Exchange Server 2013
Export a folder to pst file
Click File > Open & Export > Import/Export in Outlook 2013 and 2016. ...
In the first step of Import and Export Wizard, select Export to a file, and then click Next.
Then select Outlook Data File
Select the specified folder that you want to export as pst file in the Export Outlook Data File dialog, and click Next.

Hope this information is helpful to you.
 
Similar threads
Thread starter Title Forum Replies Date
R Flagged for Follow Up Search folder MIA after PST export/import Using Outlook 1
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
S How can I export or print a list of all my folder names in Outlook? Using Outlook 1
G Code that Runs nightly to export folder into a csv Outlook VBA and Custom Forms 1
K Disabling import/export button to restrict PST creation Using Outlook 3
R Outlook 2010 How do you export 2 email Accounts' 2010 Inbox Files to new computer (2019)? Using Outlook 0
O Export Outlook calendar appointments by filters and date range Outlook VBA and Custom Forms 1
M Export-Import .pst file problems Using Outlook 2
M How to export Voting Results with user names and their responses Outlook VBA and Custom Forms 13
J Export Zimbra to Outlook PST Using Outlook.com accounts in Outlook 1
S How to export urls from email to excel and check the status of the url ? New Slipstick.com Articles 6
C Export NSF Lotus Notes files in Outlook PST format? Using Outlook 1
C How to export Outlook data to csv? Using Outlook 0
T How to Export mailbox from Outlook 2019 to MBOX format? Using Outlook 1
M Auto-export mail to Excel Outlook VBA and Custom Forms 2
P How to export voting results using VBA? Outlook VBA and Custom Forms 2
R How To Repair OST File & Export OST File to Outlook PST ? Using Outlook 3
JohnViuf Export task list view settings to other pc Outlook VBA and Custom Forms 16
J Copy or Export Outlook Mail to Excel Outlook VBA and Custom Forms 6
N Export details to a excel spreadsheet using macros Using Outlook 0
avant-guvnor Export Calendar, Birthdays and Holidays Outlook VBA and Custom Forms 0
Diane Poremsky Export (Save) Outlook Contact photos New Slipstick.com Articles 0
K Macro to search emails between two time slots on public folders with excel export Outlook VBA and Custom Forms 12
A How to export one email data to excel Using Outlook 1
W macro to export outlook emails to excel Outlook VBA and Custom Forms 6
E Exchanger service export detection Exchange Server Administration 1
R Correct a wrong csv export file from WLM 2012 Using Outlook 0
Q Outlook 2016\365 export specific rules to import in another system Exchange Server Administration 1
H How to export *all* fields from Outlook Using Outlook 2
K Export Organizational Forms Library Exchange Server Administration 1
N Export Outlook custom forms fields to excel Outlook VBA and Custom Forms 1
E RSS export as OPML problem Using Outlook 4
A export free / busy from exchange Exchange Server Administration 0
C Export to excel missing items, but a larger total? BCM (Business Contact Manager) 6
M Outlook 2013/365 won't export 99% of my contacts to csv Using Outlook 2
T Outlook 2007 Export tasks to Excel Using Outlook 2
J Opening/Archiving/Import/Export PST files Using Outlook 4
H Select one of Contact-Mailadesses to Export > Excel or Winword Outlook VBA and Custom Forms 2
Sarge USMC Cannot import/export Outlook 13 Using Outlook 6
L Outlook 2007 Codes Export and Import Using Outlook 9
L Outlook 2007 Toolbar Export and Import Using Outlook 7
S Requried a VBA Code to export Calander details to excel... Outlook VBA and Custom Forms 4
Jennifer Murphy Can I export individual emails? Using Outlook 1
R Export Address Book VBA Using Outlook 0
W How to export additional fields in contacts Using Outlook 1
R Recover/export rules from a backup .PST Using Outlook 2
J Formatting Contacts to Export for iPhone Using Outlook 0
B No export way Using Outlook 4
F Export Outlook contacts by One Category Using Outlook 1
Jennifer Murphy Difference between export and archive? Using Outlook 10

Similar threads

Top