Windows Explored

Everyday Windows Desktop Support, Advanced Troubleshooting & Other OS Tidbits

Printing A List Of Outlook Folders

Posted by William Diaz on September 1, 2011


Besides taking screen shots of the Outlook navigation pane, there is no built in way to print or output to a file a list of folders. However, you can work around this by creating a macro in Outlook using the Visual Basic editor.

In Outlook 2010:

  1. Enable the Developer tab by going to the File tab > Customize Ribbon.
  2. Check the Developer option under the right column and click OK.
    image
  3. The Developer tab is now part of the Outlook Ribbon.
    image
  4. Select the Visual Basic button (or ALT+F11).
  5. Right-click the Module folder, then Insert > Module and name it.
  6. Copy and paste the code at the bottom of this post into the VBA Project window
    or
    Import the attached .bas file below by going to File > Import File
  7. Run the macro by clicking the Macro button. There are two options available, ExportFoldernames and ExportFolderNamesSelect:
    image
    The first one exports the currently selected folder and the second one allows you to specify a folder (or the entire mailbox). You can choose to structure or not to structure the output and a text file will be written to the desktop named outlookfolders.txt.

In Outlook 2007:

  1. Go to Tools > Macro > Visual Basic Editor (or ALT+F11).
  2. Repeat steps 5 and 6 under the 2010 instructions (if you do not have a module folder, right-click Project1 instead)
  3. Run the macro from Tools > Macro > Macros… (or ALT+F8)
    Alternatively, you can customize by adding the macro to an exiting toolbar or a new one.

 

In Outlook 2003:

  1. Go to Tools > Macro > Visual Basic Editor (or ALT+F11).
  2. Repeat steps 5 and 6 under the 2010 instructions (if you do not have a module folder, right-click Project1 instead)
  3. Run the macro from Tools > Macro > Macros… (or ALT+F8)
    Alternatively, you can customize by adding the macro to an exiting toolbar or a new one.

Get the .bas import file along with a vbs file that can run outside of Outlook here:

Or copy and paste this into the VBA Project Window:

Private MyFile As String
Private Structured As Boolean
Private Base As Integer

Public Sub ExportFolderNames()
Dim F As Outlook.MAPIFolder
Dim Folders As Outlook.Folders

Set F = Application.ActiveExplorer.CurrentFolder
Set Folders = F.Folders

Dim Result As Integer
Result = MsgBox("Do you want to structure the output?", vbYesNo + vbDefaultButton2 + vbApplicationModal, "Output structuring")
If Result = 6 Then
Structured = True
Else
Structured = False
End If

MyFile = GetDesktopFolder() & "\outlookfolders.txt"
Base = Len(F.FolderPath) – Len(Replace(F.FolderPath, "\", "")) + 1

WriteToATextFile (StructuredFolderName(F.FolderPath, F.Name))

LoopFolders Folders

Set F = Nothing
Set Folders = Nothing
End Sub

Public Sub ExportFolderNamesSelect()
Dim F As Outlook.MAPIFolder
Dim Folders As Outlook.Folders

Set F = Application.Session.PickFolder

If Not F Is Nothing Then
Set Folders = F.Folders

Dim Result As Integer
Result = MsgBox("Do you want to structure the output?", vbYesNo + vbDefaultButton2 + vbApplicationModal, "Output structuring")
If Result = 6 Then
Structured = True
Else
Structured = False
End If

MyFile = GetDesktopFolder() & "\outlookfolders.txt"
Base = Len(F.FolderPath) – Len(Replace(F.FolderPath, "\", "")) + 1

WriteToATextFile (StructuredFolderName(F.FolderPath, F.Name))

LoopFolders Folders

Set F = Nothing
Set Folders = Nothing
End If
End Sub

Private Function GetDesktopFolder()
Dim objShell
Set objShell = CreateObject("WScript.Shell")
GetDesktopFolder = objShell.SpecialFolders("Desktop")
Set objShell = Nothing
End Function

Private Sub LoopFolders(Folders As Outlook.Folders)
Dim F As Outlook.MAPIFolder

For Each F In Folders
WriteToATextFile (StructuredFolderName(F.FolderPath, F.Name))
LoopFolders F.Folders
Next
End Sub

Private Sub WriteToATextFile(OLKfoldername As String)
fnum = FreeFile()

Open MyFile For Append As #fnum
Print #fnum, OLKfoldername
Close #fnum
End Sub

Private Function StructuredFolderName(OLKfolderpath As String, OLKfoldername As String) As String
If Structured = False Then
StructuredFolderName = Mid(OLKfolderpath, 3)
Else
Dim i As Integer
i = Len(OLKfolderpath) – Len(Replace(OLKfolderpath, "\", ""))

Dim x As Integer
Dim OLKprefix As String
For x = Base To i
OLKprefix = OLKprefix & "-"
Next x

StructuredFolderName = OLKprefix & OLKfoldername
End If
End Function

Advertisements

2 Responses to “Printing A List Of Outlook Folders”

  1. […] can work around this with a macro and a little bit of VBA. You may want to enable the Developer Ribbon before hand for Office 2007/2010. Once you have, create a new module or insert the code below into […]

  2. […]   You can work around this with a macro and a little bit of VBA. You may want to enable the Developer Ribbon before hand for Office 2007/2010. Once you have, create a new module or insert the code below into […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: