Return to VBA Code Examples

VBA MkDir Statement

MkDir Description

Used to create a new folder or directory.

Simple MkDir Examples

MkDir "D:\MyFolder"

This creates a new folder “MyFolder” on the D drive.

If it already exists, it will occur a Run-time error ’75’: Path/File access error.

MkDir "MyFolder"

This creates a new folder “MyFolder” on the current folder(you can confirm the current folder using CurDir function).

MkDir Syntax

In the VBA Editor, you can type  “MkDir(” to see the syntax for the MkDir Statement:

The MkDir statement contains an argument:

Path: A string expression representing a directory.

Examples of Excel VBA MkDir Function

MkDir "D:\MyFolder\
MkDir "D:\MyFolder\AA"

This creates a new folder “MyFolder” on the D drive, and then creates a new folder “AA” on the folder “D:\MyFolder”.

MkDir "D:\MyFolder\BB\CC"

In this case, if the parent folder “D:\MyFolder\BB” exists, the above code will create a new folder “CC” on the folder “D:\MyFolder\BB”.

But, if no exist, it will occur a Run-time error ’76’: Path not found.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples