Solved

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

Posted on 2010-09-01
2
228 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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: …

776 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