excel functions

MS Excel: MKDIR Statement (VBA)

This Excel tutorial explains how to use the Excel MKDIR statement with syntax and examples.


The Microsoft Excel MKDIR statement allows you to create a new folder or directory.


The syntax for the MKDIR statement in Microsoft Excel is:

MkDir path

Parameters or Arguments

The folder or directory to create.


If path is a complex directory structure, the high-level directories must already exist or the MKDIR statement will raise an error.

For example, if you executed the following code:

MkDir "c:\Test\Excel"

The c:\Test directory must already exist. The MKDIR statement will only attempt to create the Excel directory under the c:\Test directory. It will not create the c:\Test directory itself.

Applies To

The MKDIR statement can be used in the following versions of Microsoft Excel:

  • Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Excel Function

The MKDIR statement can be used in Microsoft Excel as the following type of function:

  • VBA statement (VBA)

Example (as VBA Statement)

The MKDIR statement can only be used in VBA code in Microsoft Excel.

Let's look at some Excel MKDIR statement function examples and explore how to use the MKDIR statement in Excel VBA code:

MkDir "c:\TOTN\Examples"

In this example, the MKDIR statement would create a new directory called Examples under the c:\TOTN directory.

For example:

MkDir "c:\TOTN\Examples\Files"

In this example, the directory called Files would be created under the c:\TOTN\Examples directory.

Frequently Asked Questions

Question: I'm not sure if a particular directory exists already. If it doesn't exist, I'd like to create it using VBA code. How can I do this?

Answer: You can test to see if a directory exists using the VBA code below:

If Len(Dir("c:\TOTN\Excel\Examples", vbDirectory)) = 0 Then
   MkDir "c:\TOTN\Excel\Examples"
End If

In this example, the code would first check to see if the c:\TOTN\Excel\Examples directory exists. If it doesn't exist, the MKDIR statement would create a new directory called Examples under the c:\TOTN\Excel directory.