Link to home
Start Free TrialLog in
Avatar of A G
A GFlag for United States of America

asked on

How to modify the code so it checks the subfolders as well

I found the following code on the net. I ran this and I realize that it is looking to the folders under mailbox. But not looking to the subfolders like "Inbox". I want to be able to check subfolders too, specifically the ones under Inbox. How would I modify this code so it will look for the subfolders as well.

thanks
Dim myolApp As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim found As Boolean
    Dim strFolderName As String
    
    'specify the folder you are looking for
    strFolderName = "Inbox"
    
    found = False
    Set myolApp = GetObject(, "Outlook.Application")
    Set myNameSpace = myolApp.GetNamespace("MAPI")
    For i = 1 To (myNameSpace.Folders.Count)
        For j = 1 To (myNameSpace.Folders(i).Folders.Count)
        
'         MsgBox myNameSpace.Folders(i).Folders(j).Name
            If myNameSpace.Folders(i).Folders(j) = strFolderName Then
          
            
                Set Application.ActiveExplorer.CurrentFolder = _
                    myNameSpace.Folders(i).Folders(j)
                Exit For
            End If
        Next
        If found = True Then Exit For
    Next
    If found = True Then MsgBox "Rune Lange Sen Bir ibnesin"
    
    
    Set myolApp = Nothing
    Set myNameSpace = Nothing

Open in new window

Avatar of Zhaolai
Zhaolai
Flag of United States of America image

The following link has code to find all the folder in a mailbox:
http://www.freevbcode.com/ShowCode.Asp?ID=1064
 
ASKER CERTIFIED SOLUTION
Avatar of PJBX
PJBX
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial