VBA MkDir Statement
In this Article
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.