Solved

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

Posted on 2010-09-01
2
230 Views
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.

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

0
Comment
Question by:awesomejohn19
2 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33580249
The following link has code to find all the folder in a mailbox:
http://www.freevbcode.com/ShowCode.Asp?ID=1064
 
0
 
LVL 6

Accepted Solution

by:
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  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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