outlook-2007

Is there a macro to toggle to a specific folder in Outlook?


I often (using the mouse) switch between 1 of 3 favorite folders under my inbox. I am looking to write a macro to switch between these folders. I see lots of emails on code to move specific emails to folders but is there a way to move focus on a specific folder?


Solution

  • Sure, you could just change the CurrentFolder value to one of your Inbox folders. Here's an example of changing views from wherever I am to a folder named "T1" which is under the Inbox.

    Sub ChangeViewtoFolderT1()
    
        Dim ns As Outlook.NameSpace
        Set ns = Application.GetNamespace("MAPI")
    
        Dim Exp As Outlook.Explorer
        Set Exp = Application.ActiveExplorer
    
        Dim myInbox As Folder
        Set myInbox = ns.GetDefaultFolder(olFolderInbox)
    
        Dim folder1 As Folder
        Set folder1 = myInbox.Folders.Item("T1")
    
        Set Exp.CurrentFolder = folder1
    
    End Sub
    

    See http://msdn.microsoft.com/en-us/library/bb220039.aspx for more details.