If you want to check the size information of each folder in a PST file, you can use the method exposed in this article. It’ll quickly export the size information of all folders in a PST file to an Excel file.
When your PST file is too large, you may wish to check the size of each folder. It’ll help you easily figure out which are the larger ones and do suitable archiving on basis of the size. In general, to check the folder size, you can simply right click on a folder and then choose “Properties”. In the new popup dialog box, you can click the “Folder Size” button. However, if you have created many folders, checking the size information one by one manually is considerably troublesome. So, if you want to batch get the size information of all folders in a PST file, you can use the following VBA code. It’ll export all the folder names and size information to an Excel file in one go.
Export the Size Information of All Folders in a PST File to an Excel File
- To start with, launch your Outlook application.
- Then switch to “Developer” tab and click the “Visual Basic” button or press “Alt + F11” keys to access VBA editor.
- Next in the “Microsoft Visual Basic for Applications” window, open a module which is not in use.
- Subsequently, copy and paste the following VBA codes into this module.
Dim strExcelFile As String Dim objExcelApp As Excel.Application Dim objExcelWorkbook As Excel.Workbook Dim objExcelWorksheet As Excel.Worksheet Sub ExportFodlerSizetoExcel() Dim objSourcePST As Outlook.Folder Dim objFolder As Outlook.Folder Set objExcelApp = CreateObject("Excel.Application") Set objExcelWorkbook = objExcelApp.Workbooks.Add Set objExcelWorksheet = objExcelWorkbook.Sheets("Sheet1") objExcelWorksheet.Cells(1, 1) = "Folder" objExcelWorksheet.Cells(1, 2) = "Size" 'Select a source PST file Set objSourcePST = Outlook.Application.Session.PickFolder For Each objFolder In objSourcePST.Folders Call ProcessFolders(objFolder) Next 'Fit the columns from A to B objExcelWorksheet.Columns("A:B").AutoFit strExcelFile = "E:\Outlook\" & objSourcePST.Name & " Folder Size (" & Format(Now, "yyyy-mm-dd hh-mm-ss") & ").xlsx" objExcelWorkbook.Close True, strExcelFile MsgBox "Complete!", vbExclamation End Sub Sub ProcessFolders(ByVal objCurrentFolder As Outlook.Folder) Dim objItem As Object Dim lCurrentFolderSize As Long Dim nNextEmptyRow As Integer objCurrentFolder.Items.SetColumns ("Size") For Each objItem In objCurrentFolder.Items lCurrentFolderSize = lCurrentFolderSize + objItem.Size Next 'Convert byte to kilobyte 'To convert to megabyte, use: 'lCurrentFolderSize = (lCurrentFolderSize / 1024) / 1024 lCurrentFolderSize = lCurrentFolderSize / 1024 nNextEmptyRow = objExcelWorksheet.Range("A" & objExcelWorksheet.Rows.Count).End(xlUp).Row + 1 'Add the values into the columns objExcelWorksheet.Range("A" & nNextEmptyRow) = objCurrentFolder.FolderPath objExcelWorksheet.Range("B" & nNextEmptyRow) = lCurrentFolderSize & " KB" If objCurrentFolder.Folders.Count > 0 Then For Each objSubfolder In objCurrentFolder.Folders Call ProcessFolders(objSubfolder) Next End If End Sub
- After that, you should set your Outlook macro security level to low.
- Eventually, you can have a try.
- Press F5 key button in the current macro window.
- Then you will be requested to select a PST file, like the following image:
- After selecting a source file, Outlook will begin to export the size information to Excel.
- After macro finishes, you receive a message like the screenshot below.
- Lastly, you will be able to find the Excel file in the predefined local folder. The Excel file will look like the following:
Deal with Frequent PST Errors
Since Outlook is prone to errors, you may have ever suffered many issues in your Outlook. In order to better and more flexibly cope with frustrating PST troubles, it is advisable to keep an experienced and reputable fix utility in vicinity, such as DataNumen Outlook Repair. It is able to fix PST problems like a breeze.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including SQL Server recovery and outlook repair software products. For more information visit www.datanumen.com
This is a hugely useful tool. My thanks to Shirley Zhang for submitting the script. I’ve been able to extend it in ways that save me time on a regular basis.
This is very helpful. Is there a quick way to add a column for the number of messages, in addition to the size?
Thanks for this script… but you take all this time to write the code THEN make a very clear page on using it…. then when people bring up errors, you don’t reply?
After I got a user-defined type not defined error related to Excel.Application, I found that in vba window, I had to go into tools, references and make sure microsoft excel xx… item was checked.
But then after that, I ran the macro, it sat for a bit and I got the same runtime error 6 overflow error : (
(after getting the
Hello – I did not get that error and after adding Outlook reference object, I was able to successfully run the script. Tools-> References. The only issue I have is that size exported to excel does not match total size projected by Outlook Folder Size. I wish that can be updated and also KB to GB conversion is required in excel so that should be coded. Would it be possible to add number of emails in each folder?
when I run the code I get that error “runtime error 6 overflow”, I read about it that it could happen because of the large numbers of items i try to apply the code on, and my PST file is huge, how I can make a work around ?!