Computer programmers often create temporary files used in their applications, and it's good programming practice to delete these files when they are no longer in use. In Visual Basic for Applications, the "Kill" statement is available to delete files from a disk. This statement takes one argument that specifies one or more file names to be deleted. The argument also supports wild cards such as "*" to specify multiple files to be deleted in a folder.
- Skill level:
- Moderately Easy
Other People Are Reading
Launch Excel, click the "Developer" tab and click "Visual Basic" to open the Visual Basic Editor. Click the "Insert" menu and click "Module" to add a new module.
Create a new sub-procedure in your module by adding the following VBA code:
Private Sub deleteAllFiles().
Type the following code to create a new variable and define the path for your files:
Dim file Path As String
file Path = "C:\Temp*.*"
Use the following line of code to delete all the files in the folder you defined: Kill file Path.
Finish your sub-procedure by typing "End Sub." Press "F5" to execute the procedure.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for