Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-01
2
Medium Priority
?
239 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 2000 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Mailbox Overload?
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

926 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