Expand All Folders

This sample expands your entire folder list.

Last modified: 2007/07/31 | Accessed: 75.518  | #57
◀ Previous sample Next sample ▶
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.

Do you have an extensive folder structure and must manually open it at every startup of Outlook? Sometimes Outlook does that for you - and frequently it doesn't. This sample opens all the tree at startup, and it's a spectacle...

There's a variable 'ExpandDefaultStoreOnly' in the procedure 'ExpandAllFolders'. With the current value (True) only the Personal Folder gets expanded. If you want to expand all available mailboxes (archives, Exchange) then set the variable = False.

tip  How to add macros to Outlook
Private Sub Application_Startup()
End Sub

Private Sub ExpandAllFolders()
  On Error Resume Next
  Dim Ns As Outlook.NameSpace
  Dim Folders As Outlook.Folders
  Dim CurrF As Outlook.MAPIFolder
  Dim F As Outlook.MAPIFolder
  Dim ExpandDefaultStoreOnly As Boolean

  ExpandDefaultStoreOnly = True

  Set Ns = Application.GetNamespace("Mapi")
  Set CurrF = Application.ActiveExplorer.CurrentFolder

  If ExpandDefaultStoreOnly = True Then
    Set F = Ns.GetDefaultFolder(olFolderInbox)
    Set F = F.Parent
    Set Folders = F.Folders
    LoopFolders Folders, True

    LoopFolders Ns.Folders, True
  End If

  Set Application.ActiveExplorer.CurrentFolder = CurrF
End Sub

Private Sub LoopFolders(Folders As Outlook.Folders, _
  ByVal bRecursive As Boolean _
  Dim F As Outlook.MAPIFolder

  For Each F In Folders
    Set Application.ActiveExplorer.CurrentFolder = F

    If bRecursive Then
      If F.Folders.Count Then
        LoopFolders F.Folders, bRecursive
      End If
    End If
End Sub
OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.
email  Send a message