How to Quickly Get a List of All Outlook PST Files on Your Local Drive via VBA

If you hope to get a list of all the Outlook PST files stored on a local drive of your PC, you can utilize the piece of VBA code shown in this article. It can allow you to get it in quick time.

Quickly Get a List of All Outlook PST Files on Your Local Drive via VBA

Maybe you have created and stored many Outlook PST files on a partition of your computer. Yet, with time going on, you may forget the concrete location of these PST files. In this case, you may want to quickly find out them and achieve a list of their information, including name, size and path. In response to this requirement, here we will introduce an effective way.

Get a List of All Outlook PST Files on Your Local Drive

  1. For a start, launch your Outlook program.
  2. Then, access your Outlook VBA editor with reference to my previous article – “How to Run VBA Code in Your Outlook”.
  3. Next, copy and paste the following VBA code into “ThisOutlookSession” or an unused module.
Sub FindAllOutlookPSTFiles()
    Dim objWMIService As Object
    Dim objPSTFiles As Object
    Dim objPSTFile As Object
    Dim i As Long
    Dim objFileSystem As Object
    Dim objFolder As Object
    Dim strTextFile As String
    Dim objTextFile As Object
 
    'Find All PST Files on Drive C
    'You can change "C:" to the other drive letter as per your needs
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set objPSTFiles = objWMIService.ExecQuery ("Select * from CIM_DataFile Where Extension = 'pst' AND Drive = 'C:'")
 
    If objPSTFiles.count > 0 Then
 
       'Create a text file
       Set objFileSystem = CreateObject("Scripting.FileSystemObject")
       strTextFile = "E:\PST_Files_on_Drive_C.txt"
       Set objTextFile = objFileSystem.CreateTextFile(strTextFile, True)
 
       i = 1
 
       For Each objPSTFile In objPSTFiles
           'Input the PST file name, size and path into the text file
           objTextFile.Write (i & ". " & objPSTFile.filename & "." & objPSTFile.Extension & vbCrLf & " Size: " & objPSTFile.FileSize / 1024 & "KB" & vbCrLf & " Path: " & objPSTFile.Drive & objPSTFile.Path & vbCrLf & vbCrLf)
           i = i + 1
       Next
 
       objTextFile.Close
 
       'Open this text file
       Shell "C:\Windows\Notepad.exe " & strTextFile, 1
    Else
       MsgBox "There isn't PST file on this drive!", vbExclamation + vbOKOnly
    End If
End Sub

VBA Code - Get a List of All Outlook PST Files on Your Local Drive

  1. After that, you can try this macro right now. Just press “F5” key button.
  2. When the macro completes, you will see a text file displaying, which will look like the following screenshot:Exported List in Text File

Use Repair Tool in Case of Outlook Crashes

Assorted errors may occur to your Outlook from time to time. If you didn’t solve them in time, you will suffer severe Outlook crash one day finally. Hence, it’s right to keep a powerful and experienced PST repair utility in vicinity, like DataNumen Outlook Repair. It is especially designed to repair PST file. Thus it is capable of saving you from PST data loss.

Author Introduction:

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

Leave a Reply

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