BE CAREFULL ! this will without warning delete all Excel workbooks from said folder !!!!!!!
Sub deletefilename()
Dim fs As FileSearch
Dim fn As String
Dim rightsixfn As String
mypath = "C:\Production Files"
Set fs = Application.FileSearch
With fs
.LookIn = mypath
'.FileName = "*.*"
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
fn = .FoundFiles(i)
rightsixfn = Right(fn, 4)
If rightsixfn = ".xls" Then
Kill (fn)
End If
Next i
Else
MsgBox "There were no files found in " & mypath
End If
End With
End Sub
Thank you,
Dave Rattigan
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.