How to delete all the file in a folder from the code?

A

ana

Hi ,

I need to delete all the files in a floder from the
code ... how can I do that?

thanks
ana
 
B

Bernie Deitrick

ana,

Change the folder path/name in the macro below.

HTH,
Bernie
MS Excel MVP

Sub KillAllFiles()
Dim i As Integer
With Application.FileSearch
.NewSearch
.LookIn = "C:\Excel\Delete These"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Kill .FoundFiles(i)
Next i
End If
End With
End Sub
 
Top