Excel.Tips.Net ExcelTips (Menu Interface)

Creating a Directory in a Macro

Summary: One of the things you can do with macros is to work with disk files. As you do so, you may have a need to create a new directory in which your files can be stored. Here's how to do it. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Creating a Directory in a Macro.)

If you need to, you can create a disk-drive directory (folder) using VBA. This is done with the MkDir command, and is a remnant from the same command in earlier versions of BASIC. The syntax is:

MkDir DirName

where DirName is the full pathname of the directory you want to create. If you do not use a string variable to specify the directory name, then DirName must be enclosed in quotes. You might want to use this command if you want to create a directory where you can store temporary files you are building with your macro.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2462) applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003

You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Creating a Directory in a Macro.

Related Tips:

Your Data, Your Way! Want the greatest control possible over how your data appears on the page? Excel's custom formats can provide that control, and ExcelTips: Custom Formats can unlock the secrets to creating your own custom formats. Check out ExcelTips: Custom Formats today!