• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create Outlook Folders from a List of Folder Names

Slipstick Systems

› Developer › Code Samples › Create Outlook Folders from a List of Folder Names

Last reviewed on July 2, 2021     54 Comments

This Outlook macro creates subfolders under the currently selected folder.

Use PowerShell to add or delete folders, using a list of folders in a text file: Create new Outlook folders using PowerShell

To use, create an Excel file with the desired folder names in one column with a header row. The folder names will begin with row 2 (cell A2). You can create the file in Notepad and save it with the CSV extension.

Use Set objParentFolder = objNewFolder to create nested folders.

create new folders nested folders

Option Explicit

Public Sub MoveSelectedMessages()
    Dim objParentFolder As Outlook.Folder ' parent
    Dim newFolderName 'As String
    Dim strFilepath
    
    Dim xlApp As Object 'Excel.Application
    Dim xlWkb As Object ' As Workbook
    Dim xlSht As Object ' As Worksheet
    Dim rng As Object 'Range

    Set xlApp = CreateObject("Excel.Application")
    
    strFilepath = xlApp.GetOpenFilename
    If strFilepath = False Then
        xlApp.Quit
        Set xlApp = Nothing
        Exit Sub
    End If
      
    Set xlWkb = xlApp.Workbooks.Open(strFilepath)
    Set xlSht = xlWkb.Worksheets(1)
    Dim iRow As Integer
     
    iRow = 2
    
Set objParentFolder = Application.ActiveExplorer.CurrentFolder

While xlSht.Cells(iRow, 1) <> ""
newFolderName = xlSht.Cells(iRow, 1)
             
On Error Resume Next

Dim objNewFolder As Outlook.Folder
Set objNewFolder = objParentFolder.Folders(newFolderName)
 
If objNewFolder Is Nothing Then
    Set objNewFolder = objParentFolder.Folders.Add(newFolderName)
End If
    
    iRow = iRow + 1

 ' make new folder the parent
 ' Set objParentFolder = objNewFolder
    
  Set objNewFolder = Nothing
Wend
     
    xlWkb.Close
    xlApp.Quit
    Set xlWkb = Nothing
    Set xlApp = Nothing
    Set objParentFolder = Nothing
End Sub

Create subfolders at multiple levels

This code snippet uses the folder name in Column 1 to set the parent folder, with the new folder name in Column 2. Note that the parent folder needs to be the last one created (or the Inbox).

However, because the macro checks for the existence of the folder and creates it only if it doesn't exist, you can walk the folders to create deep subfolders. (Note: I never recommend deeply nested subfolders, it's too easy to forget where they are.)

Create subfolders

A complete copy of this macro is here

'select starting parent
Set objParentFolder = Application.ActiveExplorer.CurrentFolder
 
Dim parentname

While xlSht.Cells(iRow, 1) <> ""
parentName = xlSht.Cells(iRow, 1)
newFolderName = xlSht.Cells(iRow, 2)
            
            
 If parentName = "Inbox" Then
 Set objParentFolder = Session.GetDefaultFolder(olFolderInbox)
    Else
 Set objParentFolder = objParentFolder.Folders(parentName)
 End If
On Error Resume Next

Dim objNewFolder As Outlook.Folder
Set objNewFolder = objParentFolder.Folders(newFolderName)

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

Copy Folder Structure from Explorer into Outlook 2013

Create Outlook Folders from a List of Folder Names was last modified: July 2nd, 2021 by Diane Poremsky

Related Posts:

  • How to Create Messages Using Data in an Excel File
  • Import meetings from a CSV or XLSX file
  • Create new Outlook folders using PowerShell
  • Copy data from Outlook email tables to Excel

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
54 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Bob R
March 17, 2024 1:49 pm

Hello Diane -
I'm trying to get this to work in an Archive folder, not in my Inbox. I move project related files from my Inbox to the Archive, organized by Customer > Project Number.

I've read through all the comments below and can't get the multi-level folders to set up properly. I'm using this code. The main folders are numbered [00] Proposal, [01] Project Plan etc up to [05] Deliverables. Each main folder has sub folders. However, when I run the code, all the main folders are nested within the [00] folder. Attached are screenshots of my input file and the results are attached.

Is there something I need to change if I'm doing this in the Archive folder, instead of the inbox?

I am creating the Project folder under the customer, then selecting it as the starting folder before running the macro.

Thanks!
Bob

2024-03-17_10-34-36
2024-03-17_10-41-38
0
0
Reply
malcolm larkin
March 15, 2021 3:33 pm

Hi,
I have managed to get the macro up and running, the problem i have is there are 4 email accounts in my outlook - i would like to run this on inbox3. Any ideas would be greatly apprecited

1
0
Reply
Diane Poremsky
Author
Reply to  malcolm larkin
March 16, 2021 12:25 am

This line uses the selected folder -
Set objParentFolder = Application.ActiveExplorer.CurrentFolder

if you want to run it on the entire mailbox, select the root folder - which is usually the email address. to add the folders as subfolders of the inbox, select the inbox.

0
0
Reply
Laura
Reply to  Diane Poremsky
December 19, 2022 11:30 am

Is this the same for a shared inbox? I can get the code to work perfectly to create a two level folder structure in my own inbox, but I need to direct this to a shared inbox instead.

0
0
Reply
Diane Poremsky
Author
Reply to  Laura
December 19, 2022 2:50 pm

Because it uses the current folder - Set objParentFolder = Application.ActiveExplorer.CurrentFolder - it should work find in a shared mailbox. Select the folder where you want them created - if at the same level as the inbox, select the shared mailbox name.

0
0
Reply
malcolm larkin
March 15, 2021 3:29 pm

Hi there, the code given works brilliantly, i have however hit a barrier - I have multiple inboxes in my outlook "account1" is my default account, then there are 3 others "account2", "account3" and "account4". I would like to run this on account3 but i can not get it to work.

Any help would be greatly appreciated

0
0
Reply
Hardip Dabhi
March 2, 2021 8:04 am

Hi Developer,
I have tried to create multiple folders in the outlook 365 app but unfortunately getting the below error.

Compile error:
User-defined type not defined

error.png
0
0
Reply
Diane Poremsky
Author
Reply to  Hardip Dabhi
March 2, 2021 10:05 am

That error usually means you need to set a reference to another object model - Excel in this case - but the code as written shouldn't require that.

  1. Go to Tools, References menu.
  2. Locate the object library in the list and add a check mark to it. 

Are you adding the code to Outlook's VB Editor or Excel's ?

0
0
Reply
Hardip Dabhi
Reply to  Diane Poremsky
March 3, 2021 5:09 am

Hi Diane, I am adding this code in the Excel editor.

0
0
Reply
Diane Poremsky
Author
Reply to  Hardip Dabhi
March 3, 2021 8:10 am

As written, its an outlook macro. Switching it to an Excel macro wouldn't be difficult - mostly just the DIM lines need to be changed and outlook declared instead of Excel.

The Excel macro at Create Appointments Using Spreadsheet Data (slipstick.com) is an example.

0
0
Reply
Hardip Dabhi
Reply to  Diane Poremsky
March 4, 2021 12:12 am

Diane, I run on outlook macro and its works...
Thanks a lot man.

0
0
Reply
Karin
February 22, 2021 3:20 am

Hi there!

This works brilliantly - I used to have the macro, but forgot to back it up when I had to format my PC.

Unfortunately, the link for the complete macro links to the moving the folders macro and not creating the folders macro.

0
0
Reply
Andrew
July 24, 2020 9:58 am

Hi there!

I'm very much of a rookie to all of this.

I've got my spreadsheet with the folders i want to create and copied and pasted the above macro into the Vba thing.

Do i need to change the parts in green to match my spreadsheet?

Or do i need to import my spreadsheet somehow once i've saved the macro?

Sorry for all the basic questions!

Any help kindly appreciated

0
0
Reply
Ali
January 3, 2020 5:12 am

Hi there! I've spent like 1 hour ro figure out how to get away from the:
"Run-time error '-2147221233 (800401f)':
The attempted operation failed. An object could not be found."
But I really cannot understand, I've tried to see somewhere on Google, but nothing useful

I've 3 emails boxes in the Outlook program, I think that's the problem, but can't figure out how to solve it.
Thank you

0
0
Reply
Samuele
December 9, 2019 10:21 am

Is it possible to create a script based on the same excel file to move all emails containing the subfolder name to the created subfolders? Can you make a post about it please?

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 29

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment