Use the Kill statement with the full path of the file. The file must be closed:
Kill "C:\Reports\Old-Sales.xlsx"
Kill deletes permanently. The file does not go to the Recycle Bin, so it cannot be restored from there.
If the file is not there, Kill stops with “File not found” (error 53). Check first:
Dim filePath As String
filePath = "C:\Reports\Old-Sales.xlsx"
If Dir(filePath) <> "" Then Kill filePath
Wildcards delete several files at once. Kill "C:\Reports\*.xlsx" removes every .xlsx file in that folder, and Kill "C:\Reports\*.*" removes every file. Subfolders and the files in them are left alone. To remove a folder once it is empty, use RmDir "C:\Reports\Old".
The FileSystemObject does the same job: CreateObject("Scripting.FileSystemObject").DeleteFile "C:\Reports\Old-Sales.xlsx", True. The True argument deletes the file even if it is read-only. Its DeleteFolder method removes a folder with everything in it.
Check a wildcard before you run it. *.xl* matches .xlsx, .xlsm, .xlsb and .xlam files, so it can reach files you meant to keep. List the matches first with a Dir loop, and keep the macro file in a different folder from the files it deletes.
To delete an Excel file from a folder, you can use two different methods. The first method is the “Kill” statement which takes the file path to refer to the file that you wish to delete. The second method is the FileSystemObject object, which has a method to delete a file.
To use these codes, go to the VBE (Code Editor) from the Developer tab.
Delete a File using VBA (Kill Statement)
The Kill statement helps you delete a single file or multiple files, and you can use wildcard characters to delete more than one file. Below is the one-line code that deletes the file from the folder that I have on the desktop.
Kill "C:\Users\Dell\Desktop\Sample Data\file-one.xlsx"

This code will show you an error if the workbook that you specified to delete doesn’t exist (Error 53, File not found). It also gives an error if the file is open (Error 70, Permission denied). Kill deletes the file permanently; it doesn’t go to the Recycle Bin.
To avoid the error, check that the file exists with the Dir function before you use Kill:
Sub kill_if_exists()
Dim myFile As String
myFile = "C:\Users\Dell\Desktop\Sample Data\file-one.xlsx"
If Dir(myFile) <> "" Then
Kill myFile
Else
MsgBox "File not found."
End If
End Sub
Delete All the Files from a Folder using VBA
And if you want to delete all the Excel files that you have in a folder, you can use a wildcard character. The pattern *.xl* matches all Excel files (.xlsx, .xlsm, .xls); use *.* to delete every file in the folder.
Kill "C:\Users\Dell\Desktop\Sample Data\*.xl*"

Delete a File using the FileSystemObject (Object)
The FileSystemObject provides you with access to the computer’s file system. Now, let’s write a code to remove a file.
- First, you need to declare the variables to use in the code: one for the FileSystemObject and one for the file path.

- After that, use the CreateObject function to return the FileSystemObject and assign it to the FSO variable.

- Next, assign the path to the “myFile” variable to access the file that you wish to delete.

- In the end, use the “DeleteFile” method to delete the file.

Full Code
Sub vba_delete_file() Dim FSO Dim myFile As String Set FSO = CreateObject("Scripting.FileSystemObject") myFile = "C:\Users\Dell\Desktop\Sample Data\file1.xlsx" FSO.DeleteFile myFile, True End Sub
The True in DeleteFile is the Force argument; it deletes the file even if it’s read-only.
Let’s say you need to write a code that can check whether a file exists and then delete it. Here’s the code that you need.
Sub vba_delete_file() Dim FSO Dim myFile As String Set FSO = CreateObject("Scripting.FileSystemObject") myFile = "C:\Users\Dell\Desktop\Sample Data\file1.xlsx" If FSO.FileExists(myFile) Then FSO.DeleteFile myFile, True MsgBox "Deleted" Else MsgBox "There's no workbook with this name." End If End Sub
Delete a Folder using VBA
To delete a folder, use the RmDir statement for an empty folder, or the DeleteFolder method of the FileSystemObject, which also deletes all the files and subfolders in it (so use it carefully):
Sub delete_folder()
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists("C:\Users\Dell\Desktop\Old Data") Then
FSO.DeleteFolder "C:\Users\Dell\Desktop\Old Data", True
End If
End Sub
Note that the path for DeleteFolder must not end with a backslash.
Frequently Asked Questions
Can I delete the workbook that has the code?
Not with Kill while it’s open, as you get the Permission denied error. You can set ThisWorkbook.ChangeFileAccess xlReadOnly and then use Kill ThisWorkbook.FullName, but test it on a copy first, as the file is gone for good.
Does Kill send the file to the Recycle Bin?
No. Both Kill and DeleteFile delete the file permanently, so you can’t restore it from the Recycle Bin.
Does Kill work on a Mac?
Yes, but use a Mac path with forward slashes, like “/Users/name/Desktop/file.xlsx”. The FileSystemObject is Windows-only, so the FSO codes don’t work on a Mac.
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.