[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

OUTLOOK FOLDER NAVIGATION with VB

Posted on 2003-03-04
4
Medium Priority
?
319 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
  • 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
Today, unlike web development, the mobile landscape is complex enough for a software engineer and Android is posing more challenging environment thanks to its fragmentation issues on hardware and software fronts.
Simple Linear Regression
Screencast - Getting to Know the Pipeline

612 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