Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. 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: Removing a Directory.
by Allen Wyatt
(last updated October 5, 2019)
In other issues of ExcelTips you learn how to create a directory from within a macro. There are times that programmers (even macro programmers) create directories to store temporary files. When they are done, the files are deleted, and the directory is removed. To remove a directory, you use the RmDir command in your macro, as shown here:
where DirName is the full pathname of the directory you want to delete. If you do not use a string variable to specify the directory name, then DirName must be enclosed in quotes. If there are any files in the directory or any subdirectories contained in the subdirectory, the command fails with an error. (This means you should delete all the files and subdirectories before trying to remove a directory with RmDir.)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9935) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Removing a Directory.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
If you create a user form in VBA that includes checkboxes, you may want to make the checkboxes larger. You can't adjust ...Discover More
When you use a macro to do file operations, it works (by default) within the current directory. If you want to know which ...Discover More
When you need to stop a macro while it is running, you normally press Ctrl+Break. What are you to do if the keypress ...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.