?
Solved

OUTLOOK FOLDER NAVIGATION with VB

Posted on 2003-03-04
4
Medium Priority
?
309 Views
Last Modified: 2010-04-17
Using the code segment below I easily find current folders.  In my case, one of the folders initially availble is the 'Public Folders' folder.  I need to open this folder and find it's children and perhaps one of the childrens children.

How can I navigate down a folder hiarchy to find the folder I am interested?  Tried many approaches and have not hit on it yet.  

Thanks!


For Each olFolder In olNameSpace.Folders
    Debug.Print olFolder.Name, olApptFolder.StoreID
       
    If olApptFolder.StoreID = sOLStoreID Then
        bFolderExist = True
        Exit For
     End If
Next

0
Comment
Question by:sammydog
[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
4 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 8068714
Try using the EntryID property

Change your code to

If olApptFolder.StoreID = sOLEntryID then
...

Dabas
0
 

Accepted Solution

by:
sammydog earned 0 total points
ID: 8073121
'SammyDog says--->I found this on the web and it works great!


Public Function PSC_OUTLOOK_Folder_Find(sCalendar_Name As String) As Object
    Dim oMAPI As Outlook.NameSpace
    Dim oParentFolder As Outlook.MAPIFolder
    Dim objFolder As Outlook.MAPIFolder
   
    Dim sCurrent_FolderName As String
    Dim sCurrent_ParentName As String
     
    '* set default return value
    Set PSC_OUTLOOK_Folder_Find = Nothing
       
    '* set reference
    Set oMAPI = GetObject("", "Outlook.application").GetNamespace("MAPI")
   
'    oMAPI.Folders.Get
   
    '* get current folder name, save for reset (if needed)
    sCurrent_FolderName = oMAPI.Folders.Item(3).Name
    sCurrent_ParentName = oMAPI.Folders.Item(1).Parent
    If UCase(sCurrent_ParentName) = "MAPI" Then
        sCurrent_ParentName = sCurrent_FolderName
    End If
   
    '* -----------------------------------------------------------------
    '* set known highlevel folder
    '* -----------------------------------------------------------------
    Set oParentFolder = oMAPI.Folders("Public Folders")
   
    '* -----------------------------------------------------------------
    '* search!
    '* -----------------------------------------------------------------
    Set objFolder = PSC_Outlook_Folder_FindByName(oParentFolder, sCalendar_Name)
   
   
    '* -----------------------------------------------------------------
    'Set objFolder = OutlookFolderNames(oParentFolder, "CPC Calendars")
    'Set objFolder = OutlookFolderNames(oParentFolder, "East Coast")
    'Set oParentFolder = oMAPI.Folders(objFolder.Name)
    'Set objFolder = OutlookFolderNames(oParentFolder, "East Coast")
    '* -----------------------------------------------------------------
   
    '* was the folder located?
    If (objFolder Is Nothing) Then
        '* reset to last known highlevel folder
        Set oParentFolder = oMAPI.Folders(sCurrent_ParentName)
       
        '* reset to last folder used
        Set objFolder = PSC_Outlook_Folder_FindByName(oParentFolder, sCurrent_FolderName)
    End If
   
    '* set return value - the folder reference
    Set PSC_OUTLOOK_Folder_Find = objFolder
End Function

Function PSC_Outlook_Folder_FindByName(objFolder As Outlook.MAPIFolder, strFolderName As String) As Object
    Dim oFolder As Outlook.MAPIFolder
    Dim objOneSubFolder As Outlook.MAPIFolder

    '* #VBIDEUtils#------------------------------------------------------------
    '* Programmer Name  : Brian
    ' * E-Mail           : briannguyen7@hotmail.com
    ' * 'Date             : 11/06/2001
    ' -----------------------------------------------------------------------
    ' * Comments         : Search Outlook Folder recursively
    ' *
    ' * This snippet allows you to search for an Outlook folder within
    ' * a parent folder. Sample Usage: Dim oMAPI As Outlook.NameSpace
    ' * Dim oParentFolder As Outlook.MAPIFolder
    ' * Dim objFolder As Outlook.MAPIFolder
    ' * Set oMAPI = GetObject ("", "Outlook.application").GetNamespace("MAPI")
    ' * SetoParentFolder = oMAPI.Folders("Public Folders")
    ' * Set objFolder = OutlookFolderNames (oParentFolder, "anyfoldername")
    ' * ----------------------------------------------------------------------
    On Error GoTo ErrorHandler
   
    If Not objFolder Is Nothing Then
        If LCase(strFolderName) = LCase(objFolder.Name) Then
            Set PSC_Outlook_Folder_FindByName = objFolder
        Else
            ' Check if folders collection is not empty
            If objFolder.Folders.Count > 0 And Not objFolder.Folders Is Nothing Then
                For Each oFolder In objFolder.Folders
                    Set objOneSubFolder = oFolder               ' only check mail item folder
                   
                    If objOneSubFolder.DefaultItemType = olMailItem Or objOneSubFolder.DefaultItemType = olAppointmentItem Then '
                        If LCase(strFolderName) = LCase(objOneSubFolder.Name) Then
                            '* -------------------------------------
                            '* HIT! we found what we are looking for
                            '* -------------------------------------
                            Set PSC_Outlook_Folder_FindByName = objOneSubFolder
                            Exit For
                        Else
                            If objOneSubFolder.Folders.Count > 0 Then
                                '* -------------------------------------
                                '* RECURSION! search sub folders
                                '* -------------------------------------
                                Set PSC_Outlook_Folder_FindByName = PSC_Outlook_Folder_FindByName(objOneSubFolder, strFolderName)
                                Exit Function
                            End If
                        End If
                    End If
                Next
            End If
        End If
    End If
   
Exit Function
ErrorHandler:
    Set PSC_Outlook_Folder_FindByName = Nothing
End Function
 

0
 

Expert Comment

by:CleanupPing
ID: 9447375
sammydog:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9447889
I suggest PAQ/Refund
Asker answered his own question


Dabas
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes
Suggested Courses

801 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