none
Outlook VBA Navigation to a Favorite Folder RRS feed

  • Question

  • Hello,

    How do I navigate to a Favorite folder by name and make that active in the Navigation Pane utilizing VBA,

    I'm able to navigate to Folders utilizing VBA with no issues, just cant figure out how to navigate to Favorite and make it active

    Would be Great if someone got point me to a VBA post that shows how to this!

    Friday, March 3, 2017 3:17 PM

Answers

  • Hello,

    You can use the IsSelected property of the NavigationFolder class which allows to  set a Boolean variable that indicates whether the NavigationFolder object is selected for display.

    Also you can use the Folder property of the NavigationFolder class which returns a Folder object that represents the shared or linked folder associated with the navigation folder. Then you can set the CurrentFolder property of the Explorer class to get it shown in the main Outlook window.

    To obtain or create a new Favorites folder please see the following example:

    Private Sub CreateImportantFavoritesFolder() 
        Dim objNamespace As NameSpace 
        Dim objCalendars As Folder 
        Dim objFolder As Folder 
         
        Dim objPane As NavigationPane 
        Dim objModule As MailModule 
        Dim objGroup As NavigationGroup 
        Dim objNavFolder As NavigationFolder 
         
        On Error GoTo ErrRoutine 
         
        ' First, retrieve the default Inbox folder. 
        Set objNamespace = Application.GetNamespace("MAPI") 
        Set objCalendars = objNamespace.GetDefaultFolder(olFolderInbox) 
         
        ' Create a new mail folder named "Important Items". 
        Set objFolder = objCalendars.Folders.Add("Important Items") 
             
        ' Get the NavigationPane object for the 
        ' currently displayed Explorer object. 
        Set objPane = Application.ActiveExplorer.NavigationPane 
         
        ' Get the mail module from the Navigation Pane. 
        Set objModule = objPane.Modules.GetNavigationModule(olModuleMail) 
         
        ' Get the "Favorite Folders" navigation group from the 
        ' mail module. 
        With objModule.NavigationGroups 
            Set objGroup = .GetDefaultNavigationGroup(olFavoriteFoldersGroup) 
        End With 
         
        ' Add a new navigation folder for the "Important Items" 
        ' folder in the "Favorite Folders" navigation group. 
        Set objNavFolder = objGroup.NavigationFolders.Add(objFolder) 
         
    EndRoutine: 
        On Error GoTo 0 
        Set objNavFolder = Nothing 
        Set objFolder = Nothing 
        Set objGroup = Nothing 
        Set objModule = Nothing 
        Set objPane = Nothing 
        Set objNamespace = Nothing 
        Exit Sub 
     
    ErrRoutine: 
        MsgBox Err.Number & " - " & Err.Description, _ 
            vbOKOnly Or vbCritical, _ 
            "CreateImportantFavoritesFolder" 
    End Sub 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, March 3, 2017 4:28 PM

All replies

  • Hello,

    You can use the IsSelected property of the NavigationFolder class which allows to  set a Boolean variable that indicates whether the NavigationFolder object is selected for display.

    Also you can use the Folder property of the NavigationFolder class which returns a Folder object that represents the shared or linked folder associated with the navigation folder. Then you can set the CurrentFolder property of the Explorer class to get it shown in the main Outlook window.

    To obtain or create a new Favorites folder please see the following example:

    Private Sub CreateImportantFavoritesFolder() 
        Dim objNamespace As NameSpace 
        Dim objCalendars As Folder 
        Dim objFolder As Folder 
         
        Dim objPane As NavigationPane 
        Dim objModule As MailModule 
        Dim objGroup As NavigationGroup 
        Dim objNavFolder As NavigationFolder 
         
        On Error GoTo ErrRoutine 
         
        ' First, retrieve the default Inbox folder. 
        Set objNamespace = Application.GetNamespace("MAPI") 
        Set objCalendars = objNamespace.GetDefaultFolder(olFolderInbox) 
         
        ' Create a new mail folder named "Important Items". 
        Set objFolder = objCalendars.Folders.Add("Important Items") 
             
        ' Get the NavigationPane object for the 
        ' currently displayed Explorer object. 
        Set objPane = Application.ActiveExplorer.NavigationPane 
         
        ' Get the mail module from the Navigation Pane. 
        Set objModule = objPane.Modules.GetNavigationModule(olModuleMail) 
         
        ' Get the "Favorite Folders" navigation group from the 
        ' mail module. 
        With objModule.NavigationGroups 
            Set objGroup = .GetDefaultNavigationGroup(olFavoriteFoldersGroup) 
        End With 
         
        ' Add a new navigation folder for the "Important Items" 
        ' folder in the "Favorite Folders" navigation group. 
        Set objNavFolder = objGroup.NavigationFolders.Add(objFolder) 
         
    EndRoutine: 
        On Error GoTo 0 
        Set objNavFolder = Nothing 
        Set objFolder = Nothing 
        Set objGroup = Nothing 
        Set objModule = Nothing 
        Set objPane = Nothing 
        Set objNamespace = Nothing 
        Exit Sub 
     
    ErrRoutine: 
        MsgBox Err.Number & " - " & Err.Description, _ 
            vbOKOnly Or vbCritical, _ 
            "CreateImportantFavoritesFolder" 
    End Sub 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, March 3, 2017 4:28 PM
  • Could you please post an example on how to achieve setting a favorite active and displayed

    I'm able to set folders active but not favorites.

    Thanks

    Friday, March 3, 2017 4:47 PM
  • Thanks for the point in the right Direction

    Below does what I needed.

    objGroup.NavigationFolders.Item("Mail to Read").IsSelected=True

    Friday, March 3, 2017 7:07 PM