VBA MkDir Statement
In this Article
Used to create a new folder or directory.
Simple MkDir Examples
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.
This creates a new folder “MyFolder” on the current folder(you can confirm the current folder using CurDir function).
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”.
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 EasyStop 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!