Creating Folders

The MkDir function is used to create Windows folders from VBA. Some examples of MkDir are:

Create a folder called DicksStuff under the current directory
MkDir “DicksStuff”
MkDir “DicksStuff”
MkDir “DicksStuff”

Create a folder on the C drive regardless of the current drive or directory
MkDir “C:DicksStuff”
MkDir “C:DicksStuff”

Create a folder one directory back from the current directory
MkDir “..DicksStuff”

Create a folder at the root directory of the current drive
MkDir “.DicksStuff”

You can’t create more than one level at a time. If you want to create C:DicksStuffPrivate, you have to issue two MkDir functions

MkDir “C:DicksStuff”
MkDir “C:DicksStuffPrivate”

If you try to MkDir a directory that already exists, you get an error (which is just silly). Use an On Error statement to avoid an error if the directory may exist.

Posted in Uncategorized


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.