Written by Allen Wyatt (last updated April 17, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
Sometimes you may use a macro to create temporary files which you later need to delete. Similarly, you may need to just delete a file within a macro. You can accomplish this task using the Kill command. This is a holdover from other versions of BASIC. The syntax is:
Kill File
where File is the full path and file name of the file you want to delete. When you delete a file in this manner, the file is not moved to the Windows Recycle bin; instead, it is immediately deleted from your drive.
If desired, you can also use wildcard characters in the File specification. For instance, if you wanted to delete all the files in the current directory that end in the TMP extension, you could use a command like this:
Kill "*.tmp"
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10001) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Deleting a File in a Macro.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Paste Special is a great tool that allows you to modify the values in a range of cells in your worksheets. You may want, ...
Discover MoreLogical structures are important in programming, as they allow you to control how the programming statements are ...
Discover MoreMacros can be used to change the formatting of your worksheet, if desired. One change you might want to make is to the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments