How to Get Warned When Your Outlook PST File Exceeds a Predefined Size Limit

In order to protect your Outlook data against corruption, you should keep paying attention to the size of your Outlook PST file. This article will teach you how to let Outlook warn you when your PST file exceeds a predefined size limit.

With your Outlook PST file larger and larger, the file will be becoming more prone to corruption as well. Hence, you have to always keep your Outlook PST file in small size. As for how to check the size of your PST file, in general, you can use two methods.

One is to find the PST file in your local hard drive and then check its size. The other one is to make use of “Archive” feature. You can go to “File” menu and click on the “Cleanup Tools” button and select “Mailbox Cleanup”. In the popup dialog box, you can see the size of your default Outlook PST file. However, you may feel that manually checking the file size is a bit troublesome. Perhaps you hope that Outlook can automatically check the file size and give you a warning when the file exceeds a specific size limit, such as 20 MB. In response to this requirement, you could use the following VBA codes to achieve it.

VBA Code - Get Warned When Your Outlook PST File Exceeds a Predefined Size Limit

Get Warned When Your Outlook PST File Exceeds a Predefined Size Limit

  1. At the very outset, start your Outlook program.
  2. Then in the main Outlook window, press “Alt + F11” key shortcuts to access VBA editor.
  3. Next in “Microsoft Visual Basic for Applications” window, you should open the “ThisOutlookSession” project.
  4. Subsequently, you need to copy and paste the following VBA codes into this project window.
Private Sub Application_Startup()
    Call GetAllFolders
End Sub

Private Sub GetAllFolders()
    Dim objFolders As Outlook.Folders
    Dim objFolder As Outlook.Folder
    Dim lFolderSize As Long
    Dim strMsg As String
    Dim nWarning As Integer
 
    lFolderSize = 0
 
    'Change "John Smith" to the name of your Outlook PST file
    Set objFolders = Outlook.Application.Session.Folders("John Smith").Folders
 
    For Each objFolder In objFolders
        Call GetFileSize(objFolder, lFolderSize)
    Next
 
    'Convert the bytes to mega bytes
    lFolderSize = (lFolderSize / 1024) / 1024
 
    'Change "20" MB as per your needs
    If lFolderSize > 20 Then
       strMsg = "Your mailbox is " & lFolderSize & " MB, which is large. " & vbCrLf & "Please archive old and useless items right now!"
       nWarning = MsgBox(strMsg, vbExclamation + vbOKOnly, "Check MailBox Size")
    End If
End Sub
 
Private Sub GetFileSize(objCurrentFolder As Outlook.Folder, lCurrentFolderSize As Long)
    Dim objSubFolder As Outlook.Folder
    Dim objItem As Object
 
    'Count the total size of all items
    For Each objItem In objCurrentFolder.Items
        lCurrentFolderSize = lCurrentFolderSize + objItem.Size
    Next
 
    'Process all the subfolders recursively
    If (objCurrentFolder.Folders.Count > 0) Then
        For Each objSubFolder In objCurrentFolder.Folders
            Call GetFileSize(objSubFolder, lCurrentFolderSize)
        Next
    End If
End Sub

VBA Code - Get Warned When Your Outlook PST File Exceeds a Predefined Size Limit

  1. After that, sign this code.
  2. Later change your Outlook macro settings to permit the signed macros.
  3. From now on, every time when you start Outlook, Outlook will auto check the size of your specific Outlook PST file. If the file exceeds the specific size. you will get a warning like the following screenshot:Warning

Tackle Bothersome PST Troubles

As Outlook PST is susceptible to errors and corruption, you should make efforts to safeguard your valuable PST data, such as keeping your PST file in small size, making regular backups for your PST file and getting hold of a reliable Outlook repair tool like DataNumen Outlook Repair. It can help you get rid of various PST issues in quick time.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including SQL Server repair and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.