Export folder names to a file

While Outlook holds several exporting options for messages, it does not have an option to export a list of folder names. A common workaround suggested is to use screenshots instead. This (an image) is often not a very practical output format.

Even though several screenshot applications also have text recognition and can export the contents to a text file, it usually still is cumbersome. While the end-result will improve, it often isn't very workable when you have long folder names or a deep rooted system as the names might get truncated in the windows you are taking a screenshot of.

A much more direct solution would be to use a script to generate the txt-file by querying Outlook for the folder names itself. This guide provides 2 methods to do that; via a VBScript file that can run outside of Outlook (quickest method) and by using a macro.

Quickest method to export the folder names

If you just want to get your export as quickly as possible use the instructions below;

  1. Download this code-file (exportoutlookfolders.zip)
  2. Open or extract the zip-file and double click on exportoutlookfolders.vbs
  3. Select the mailbox or folder you want to export the folder names of.
  4. Select whether you want to structure the output or not (see the example screenshots below).
  5. Within a few seconds the file outlookfolders.txt will appear on your Desktop containing the exported folder names.

You're done! When you want to use the script from within Outlook instead; feel free to continue reading ;-).

When you run exportoutlookfolders.vbs again, your new results will be appended to the outlookfolders.txt file.

Installing the macro (quick)

If you are already (somewhat) familiar with using VBA code in Outlook, you can use the installation instructions below. If you are not familiar with using VBA code in Outlook yet, click here to jump to the step-by-step part of the guide with more detailed installation instructions.

  1. Download this code-file (exportoutlookfolders.zip) or copy the code below.
  2. Open the VBA Editor (keyboard shortcut ALT+F11)
  3. Extract the zip-file and import the bas-file via File-> Import…
    If you copied the code paste it into a new module.
  4. Sign your code.
  5. Add a button for easy access to the macro or press ALT+F8 and the macro you want to execute (for usage details see the Using the macro section)..

If you've done things correctly, your macro should work now. If it doesn't, retrace your steps by following the step-by-step instructions below.

Installing the macro (step-by-step)

As I already provide you with the code, creating the macro is easy. The code should work for all supported Outlook and Windows combinations. It has been tested with Outlook 2002/XP and Outlook 2003 on Windows XP and with Outlook 2007 and Outlook 2010 on Windows 7.

Open the VBA Editor

Installing the macro goes via the VBA Editor in Outlook. In order to open it you can use the keyboard shortcut ALT+F11 or via;

  • Outlook 2007 and previous
    Tools-> Macro-> Visual Basic Editor
  • Outlook 2010
    tab Developer-> button Visual Basic

By default the Developer tab is hidden in Outlook 2010. To enable it use;
File-> Options-> Customize Ribbon-> enable the checkbox in front of Developer in the most right column.

Developer tab in Outlook 2010
You'll need to enable the Developer tab in Outlook 2010 first.

Creating the Macro

After opening the VBA Editor, you can directly import the code by downloading this zip-file (exportoutlookfolders.zip). Once you've extracted the zip-file, you can then easily import it via; File-> Import…
Browse to the directory where you extracted the zip file and select the file: exportfolders.bas

You can download and extract the zip-file to your Desktop for easy access to it. Once you've imported it, you can remove it from your Desktop again.

If you want to do it manually, you'll first have to create a new module via;
Insert-> Module

Select the newly created module in the left pane and rename it to "ExportFolders" by changing the Properties value in the pane underneath. Copy and paste the code below to the module.

Click in the area above and press CTR+A to select all. Press CTRL+C to copy the code.

The code copied in the Visual Basic Editor. (Click on image to enlarge)
The code copied in the Visual Basic Editor. (Click on image to enlarge)

Debug the code

Once you've copied over the code and (optionally) made any modifications to it, we now have to debug the code by choosing Debug-> Compile Project1.

You shouldn’t be getting errors if you’ve done everything correctly.
If you do get errors, retrace your steps and also verify that any previous code you might have in ThisOutlookSession is correct. If you made modifications to the code, copy over the code as given above and test if that works for you first. Debug until you’ve solved the errors (the code provided works correctly without any modifications).

To be able to run the code without setting your macro security level to medium I recommend that you sign your code which is a very easy process and only takes a minute.

Using the macro

Now that you've added the OutlookFolders module, you'll see 2 new macros added to the macro selector (keyboard shortcut ALT+F8);

  • ExportFolderNames
    The ExportFolderNames macro will directly export the folder names starting at the currently selected folder.
  • ExportFolderNamesSelect
    The ExplortFolderNamesSelect macro will prompt you to select a starting folder. This is mainly to accommodate for exporting folder lists of an entire IMAP mailbox store (as you cannot select the root folder).

A better method to have quick access to a macro is to create button for it. This button can be customized with an image and allows itself to be activated with a single mouse click or a direct keyboard shortcut.
To find out more see: Create a button for a macro

ExportFolders icon
The ExportFolders icon in the Toolbar.

Structuring the output
When executing the macro, you'll be prompted whether or not you want to structure the output.

  • No structuring (Default)
    If you choose "No" (default), the output will list all the folder names with their folder path in full.
  • Structuring
    If you choose "Yes", only the folder names will be exported. A hyphen character "-" will be placed in front of the folder name to indicate when a folder is a sub folder. A folder that is for instance rooted 3 levels deep when compared to the start folder will have 3 hyphen characters in front of it.

Output Examples

Unstructured output of Outlook's folder list
Unstructured output.
Structured output of Outlook's folder list
Structured output.