Free for PREMIUM members
[Webinar] Streamline your web hosting managementRegister Today
Public Sub CountFoldersInOutlook()
Dim outapp As Outlook.Application
Set outapp = CreateObject("Outlook.Application")
Dim olns As Outlook.NameSpace
Set olns = outapp.GetNamespace("MAPI")
MsgBox "Total Folders: " & GetSubFolderCount(olns.GetDefaultFolder(olFolderInbox).Parent)
Private Function GetSubFolderCount(objParentFolder As MAPIFolder) As Long
Dim currentFolders As Folders
Dim fldCurrent As MAPIFolder
Set currentFolders = objParentFolder.Folders
If currentFolders.Count > 0 Then
Set fldCurrent = currentFolders.GetFirst
While Not fldCurrent Is Nothing
TempFolderCount = TempFolderCount + GetSubFolderCount(fldCurrent)
Set fldCurrent = currentFolders.GetNext
GetSubFolderCount = TempFolderCount + currentFolders.Count
GetSubFolderCount = 0
Public Sub CountItemsInOutlook()
Dim objOutlook As Object, objnSpace As Object, objFolder As MAPIFolder, objSubFolder As MAPIFolder
Dim EmailCount As Integer
Dim nFolder as Long, nFolders as Long, nSubFolders as Long, nSubFolder as Long
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
nFolders = objnSpace.Folders.Count
For nFolder = 1 To nFolders
Set objFolder = objnSpace.Folders(nFolder)
nSubFolders = objFolder.Folders.Count
For nSubFolder = 1 To nSubFolders
Set objSubFolder = objFolder.Folders(nSubFolder)
nItems = nItems + objSubFolder.Items.Count
EmailCount = nItems
MsgBox "Total number of items (all folders) : " & CStr(nItems)
Open in new window
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $39.20.
Premium members get this course for $159.20.
Premium members get this course for $31.25.
Premium members get this course for $12.50.
Premium members get this course for $37.50.
Premium members get this course for $168.80.
Premium members get this course for $174.99.