If there are sub folders within main Inbox or Sent Items folder, how to go about traversing them in a recursive and efficient way, using VBA, is a very useful tip. This critical piece is reusable in many other VBA projects.
The Critical Problem of Traversing Folders

Outlook VBA Script
Below is the complete Outlook VBA script:
Private Sub Main()
Dim objNameSpace As Outlook.NameSpace
Dim objMainFolder As Outlook.Folder
Set objNameSpace = Application.GetNamespace("MAPI")
Set objMainFolder = objNameSpace.GetDefaultFolder(olFolderInbox)
Call ProcessCurrentFolder(objMainFolder)
End Sub
Private Sub ProcessCurrentFolder(ByVal objParentFolder As Outlook.MAPIFolder)
Dim objCurFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
On Error Resume Next
' Process each items in the folder
For Each objMail In objParentFolder.Items
' Do your task here ...
Next
' Process the subfolders in the folder recursively
If (objParentFolder.Folders.Count > 0) Then
For Each objCurFolder In objParentFolder.Folders
Call ProcessCurrentFolder(objCurFolder)
Next
End If
End Sub
How to Run the Script
Press Alt + F11 to open the Outlook VBA editor and paste the above code in “ThisOutlookSession”. It is important to know that prior to running this script, Microsoft Outlook XX Object library should be added to the project references from “Tools” menus, where XX is the library version.
Understand the Script

Recover from Disaster
If you are faced with a situation of Outlook crash or failure, there is no need to worry about the lost emails, as DataNumen shall brings your life back to normal by fixing Outlook corruption in an efficient way.
Author Introduction:
Mary Underwood is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including dwg recovery and rar recovery software products. For more information visit www.datanumen.com