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

Posted on 2010-09-01
Last Modified: 2012-06-22
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.

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 = _


                Exit For

            End If


        If found = True Then Exit For


    If found = True Then MsgBox "Rune Lange Sen Bir ibnesin"



    Set myolApp = Nothing

    Set myNameSpace = Nothing

Open in new window

Question by:awesomejohn19
LVL 17

Expert Comment

ID: 33580249
The following link has code to find all the folder in a mailbox:

Accepted Solution

PJBX earned 500 total points
ID: 33709509
Declare mysubfolder varialbe and add it within the loop of the main folders.

Dim mysubfolder As Outlook.MAPIFolder
For Each mysubfolder In myfolder.Folders  

Next mysubfolder  

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now