If you want to copy the folder structure from one Outlook PST file to another, you can use the method introduced in this article, which will teach you how to use VBA to get it in one go.
Perhaps, in order to better manage your emails, you have created several custom folders in your main Outlook file. Thus when creating a new Outlook PST file, you may want to apply the same folder structure. Actually, in my previous article – “2 Steps to Keep the Current Folder Hierarchy in a New Outlook File”, you can learn a traditional method, which is using “Archive” feature to achieve it. Nevertheless, actually, it is still a bit tedious. Compared with it, using VBA codes to get it will be much quicker. Therefore, in the followings, we’ll tell you the elaborate steps and codes.
Copy Folder Structure from One Outlook PST File to Another
- At the very outset, start your Outlook program.
- Then in the Outlook window, press “Alt + F11” key buttons.
- Next you will enter the Outlook VBA editor window.
- Subsequently, copy and paste the following VBA codes into a new module.
Public objNewPSTFolder As Outlook.Folder Sub CopyFolderStructure() Dim objFolders As Outlook.Folders Dim objFolder As Outlook.Folder 'Get the folders of the source Outlook PST file Set objFolders = Outlook.Application.Session.Folders("Personal").Folders 'Create the new pst file in your desired local folder and name Outlook.Application.Session.AddStore "E:\New PST File.pst" Set objNewPSTFolder = Session.Folders.GetLast() For Each objFolder In objFolders CreateFolder objFolder Next MsgBox "Completed!", vbOKOnly + vbInformation, "Copy Folder Structure" End Sub Sub CreateFolder(objFolder As Outlook.Folder) Dim objSubFolder As Outlook.Folder 'Only copy the mail folder If (objFolder.DefaultItemType = olMailItem) Then 'New Outlook PST file auto includes the "Deleted Items" folder, so skip it 'Skip the useless mail folders - "Conversation Action Settings" and "Quick Step Settings" If (objFolder.Name <> "Deleted Items") And (objFolder.Name <> "Conversation Action Settings") And (objFolder.Name <> "Quick Step Settings") Then 'Create the new folder objNewPSTFolder.Folders.Add objFolder.Name Set objNewPSTFolder = objNewPSTFolder.Folders.Item(objFolder.Name) For Each objSubFolder In objFolder.Folders CreateFolder objSubFolder Next Set objNewPSTFolder = objNewPSTFolder.parent End If End If End Sub
- After that, change your macro security level to low.
- Later back to VBA editor window and press “F5” key button to run the macro.
- Finally, after the macro finishes working, you will get a message, prompting “Completed!”.
- At this point, you can go to the mail navigation pane. You’ll see a new Outlook Data File which is in the same folder structure as the source PST file, like the image below:
Cope with Dispiriting PST Troubles
As Outlook PST is error prone, many of you must have ever encountered various issues in Outlook. Faced with them, you can firstly use Outlook inbox repair tool to have a try. If it fails, you can then apply a more potent third party tool, such as DataNumen Outlook Repair, which can fix Outlook PST errors like a breeze.
Author Introduction:
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including SQL Server fix and outlook repair software products. For more information visit www.datanumen.com
Leave a Reply