VBA Code to Delete File

Complete Excel VBA Course

In this article we are going to show you how you can delete file or files using a single line of VBA code.

There are three types of deletion you may want to perform:

1. Delete a specific file from the folder

VBA Code to Delete File
Here is the VBA code to delete a file from the folder.
Kill "E:\Work\ExcelSirJi\ Test 3.txt"

2. Delete specific type of files from the folder.

For example, you may want to delete all .txt files from the folder and do not want to delete any other types of files.

Here is the VBA code to delete specific types of files from the folder:
Kill "E:\Work\ExcelSirJi\*.txt"

3. Delete all files from the folder

Here is the VBA Code to delete all files from the folder:
Kill "E:\Work\ExcelSirJi\*"

How can I use this VBA code?

If you want to use this code in your VBA tool, then follow below steps:

Step 1: Open the Excel file in which you want to copy this code

Step 2: Press Alt+F11

Step 3: Open the module in which you want to add this code

Step 4: Paste this code just after the code where you want to delete the file(s)
VBA Code to Delete File

What will happen when I run this code?

The code will delete file(s) from the given folder

Complete Excel VBA Course

Thanks for reading the article, subscribe us to get more VBA tricks

Download Practice File

You can also practice this through our practice files. Click on the below link to download the practice file.

Recommended Articles

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Excel VBA Course : Beginners to Advanced

We are offering Excel VBA Course for Beginners to Experts at discounted prices. The courses includes On Demand Videos, Practice Assignments, Q&A Support from our Experts. Also after successfully completion of the certification, will share the success with Certificate of Completion

This course is going to help you to excel your skills in Excel VBA with our real time case studies.

Lets get connected and start learning now. Click here to Enroll.

Similar Posts

2 Comments

    1. Just want to check, are you not able to copy the codes from the article. You can use these same codes for your requirements. Let us know if you have any other challenges.

Leave a Reply

Your email address will not be published. Required fields are marked *