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.
Author Introduction:
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
I use VBA a lot in Excel but this is the first with Outlook for me.
When I run your code I get Compile error: User-defined type not defined
for Dim objExcelApp As Excel.Application
Would you suggest how to fix this?
Found a note about Microsoft Solutions that suggested Visual Studio.
I have Visual Studio downloaded but do not know what workload to choose
to work with VBA
Yes! Finally something about %keyword1%.
The fix to my second comment was to change line 26 to whatever folder structure you actually have. Now it works for me.
So I chose the top level folder, i.e. the account named by the email address, in the popup dialogue box and my first error (’91’) went away but I get another error:
Run-time error ‘1004:
Microsoft Excel cannot access the file ‘E:\Outlook\C8DB2300’. There
are several pyssible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a
currently open workbook.
After I fixed the user-defined type error (that Tom gave the fix for) I got an error that says, “Run-time error ’91’: Object variable or With block variable not set”.
: /
This works great but only pulls the local data size. Can you edit it to pull the server data size?
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?
Hello,
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 ?!