i want to loop through a tree of nested folders from Outlook, and to do so i have written a subroutine that loops through one folder, and for each subfolder it calls itself. however, after looping the first subfolder, it never returns to the main sub.
a simplified code sample:
Expand|Select|Wrap|Line Numbers
- Sub LoopFolder(ByVal objFolder As Outlook.MAPIFolder)
- Dim FolderItem As Object
- ' Look for subfolders. Call this sub for any found folders
- If objFolder.Folders.Count > 0 Then
- For Each FolderItem In objFolder.Folders
- MsgBox "entering subfolder " & intCtr & " of " & objFolder.Folders.Count & "..."
- Call LoopFolder(objFolder.Folders(FolderItem.Name))
- MsgBox "exiting subfolder..."
- Next FolderItem
- End If
- Dim MailItem As Object
- If objFolder.Items.Count > 0 Then
- For Each MailItem in objFolder.Items
- MsgBox "email found!"
- Next MailItem
- End If
- End Sub
but why does it exit instead of returning back to the "parent" sub?