VBA Code to Delete File


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
VBA Code to Delete File
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

VBA Code to Delete File
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

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

Leave a Reply

avatar
VBA Code to Count Cells by Color
VBA TRICKS
VBA Code to Count Cells by Color

Have you ever felt that Microsoft should have added a formula in Excel which can count the cells based on specific color? I have seen many code requests to share a VBA code that can count the cells by its color. To help our subscribers and developers, we are sharing 2 codes that be used to count the cells with specific color and returns the count of the matching color cells.

VBA Code to Sum Cells by Color
VBA TRICKS
VBA Code to Sum Cells by Color

Recently some of our subscribers have requested us to share a VBA code that can sum the cells by its color. To help our subscribers and developers, we are sharing 2 codes that be used to sum the cells with specific color and returns the total sum of the matching color cells

FREE VBA UTILITIES
35
VBA Tool to Track Start and End Time (Time & Motion Tracker)

Here is one more wonderful free tool from ExcelSirJi.com which makes your life easy. Time & Motion Tracker helps you to track Start and End time of any type of transaction or activity. The good thing is, it is VBA based tool which helps you to protect from manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time

error

Like the Article? Please spread the word :)

Facebook
Facebook
YouTube
YouTube
Pinterest
Pinterest
LinkedIn