Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Creating a Directory in a Macro.
by Allen Wyatt
(last updated May 12, 2016)
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:
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 (8851) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Creating a Directory in a Macro.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...Discover More
Normally a macro is only calculated when you specifically tell Excel to calculate it. Some macros need to be calculated ...Discover More
The security features built into Excel allow you to digitally sign your macros so that users can rest assured that they ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.