How to Make a Free Compact PST Tool via Outlook VBA

If you want to compact your Outlook data file, in general, you will select to use the “Compact Now” feature in Outlook. But it has some drawbacks. Thus, in this article, we will teach you to make a more robust compact PST tool via VBA.

As we all know, Outlook file will be susceptible to errors and corruption as the file becomes increasingly larger. Therefore, you should pay much attention to the size of your Outlook file to keep it in small size. Apart from removing the useless and old items, you can also compact the Outlook data file to reduce its size.

Make a Free Compact PST Tool via Outlook VBA

About Inbuilt “Compact Now” Feature

Perhaps you have found that Outlook comes with a native “Compact Now” feature. After launch your Outlook program, in mail navigation pane, you can right click on the Outlook data file which you want to compact. Then from the context menu, select “Data File Properties”. Next in the subsequent dialog box, hit the “Advanced” button. Later you will be able to find the “Compact Now”. Although such a feature is handy, it still has many shortcomings.

Inbuilt “Compact Now” Feature

The huge disadvantage is that if the source Outlook data file is considerably large, it will take a pretty long time to accomplish the compression process. Moreover, the source Outlook data file must have been utilized for a long time, thus, it may contain a lot of hidden errors. The “Compact Now” function cannot help you get rid of these internal errors.

Compared with this inbuilt utility, another compact PST tool, which we will teach you to make in the followings, doesn’t have these drawbacks. It can work much faster even if the source file is blazing large. Now please read on. We’ll expose the elaborate steps and VBA codes.

Make a Free Compact PST Tool for Outlook File

  1. In the first place, press “Alt + F11” key buttons in main Outlook window.
  2. Next you can open a module which is not in use or insert a new module.
  3. Then copy and paste the following VBA codes into this module.
Private Sub CompactPSTFile()
    Dim objSourceFileFolders As Outlook.Folders
    Dim objFolder As Outlook.Folder
    Dim objNewPSTFileFolder As Outlook.Folder
    'Create a new PST file in the predefined local folder and file name
    Outlook.Application.Session.AddStore "E:\NewPST.pst"
    Set objNewPSTFileFolder = Session.Folders.GetLast()
    'Get all the folders of the source PST file
    'Change the "Personal" to the source PST file display name
    Set objSourceFileFolders = Outlook.Application.Session.Folders("Personal").Folders

    For Each objFolder In objSourceFileFolders
        objFolder.CopyTo objNewPSTFileFolder
End Sub

VBA Code - Make a Free Compact PST Tool

  1. After that, you should set your Outlook macro security level to low.
  2. Finally you can trigger the subroutine by clicking the “Run” icon or pressing F5 key in the macro window,
  3. At once, a new Outlook data file will show up in the navigation pane, which is compressed from the source Outlook file.

Avoid Miserable PST Data Corruption

As what I mentioned at the very beginning of this article, Outlook PST file will be prone to corruption when it is too large. Therefore, apart from keeping it in small size, you need to back it up regularly. In this way, even if the file suffers errors or corruption, you still can easily get back corrupt PST data from backups. It will be very convenient.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted mdf and outlook repair software products. For more information visit

Leave a Reply

Your email address will not be published. Required fields are marked *