Expand All Folders

This sample expands your entire folder list.

Last modified: 2007/07/31 | Accessed: 48.363  | #57
◀ Previous sample Next sample ▶
Category-Manager Category-Manager
Access the master category list in the blink of an eye, share your color categories in a network, get a reminder service, and more.

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
SAM automatically sets the sending account, or sender address, and folder for sent items based on several criteria.
email  Send a message