Display a notification when the PST file reaches the size limit (VBA)

Introduction

This VBA sample illustrates how to prompt a warning message when Outlook is starting if the PST file size reaches the limit. It can be run on Outlook 2007 and 2010.

Scenarios

ITPros find a lot of issues caused by the large PST file. This VBA can help ITPros to reduce their workload and prevent potential Outlook issues.

Script

Step1. Press Alt+F11 to open the VBE in Outlook.

Step2. Drag the "PSTChecker.bas" file to the Project Explorer (Press Ctrl+R if you cannot see it) or via File >> Import File... (Ctrl+M).

Step3. Copy the following code to ThisOutlookSession.

Option Explicit

' Check the PST file size when Outlook is starting.
Private Sub Application_Startup()
    CheckPstFileSize
End Sub

Step4. Save VbaProject.OTM (Ctrl+S) and then restart Outlook.

Note

1. Please make sure that macros are enabled in Outlook.

For Outlook 2007:
Tools >> Macro >> Security... >> Macro >> Security >> No security check for macros >> OK >> Restart Outlook

 For Outlook 2010:
File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Enable all macros >> OK >> OK >> Restart Outlook

2. In the "PSTChecker.bas" file, the maximum size limit for a PST file is 2147483648 KB (2 GB). You can change the size limit from this code line:

' 1 GB = 1024 MB = 1024 KB = 1024 Bytes
Private Const MAX_PSTSIZE_LIMIT = 2147483648#

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

VB Script
Edit|Remove
If lngLength > 0 Then 
        For lngLoop = 1 To lngLength Step 2 
            strTemp = strTemp & ChrW("&H" & Mid$(StoreID, lngLoop, 2)) 
        Next 
         
        strTemp = Replace(strTemp, Chr(0), vbNullString) 
        lngPosition = InStr(1, strTemp, ":\", vbTextCompare) 
         
        If lngPosition <> 0 Then 
            ExtractPathFromStoreID = Right$(strTemp, Len(strTemp) - lngPosition + 2) 
        End If 
    Else 
        ExtractPathFromStoreID = "" 
    End If

Additional Resources

Related forum threads