Solved

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

Posted on 2010-09-01
2
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

752 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