Hi,
I use the code below to delete all xl files at a certain destination on a weekly basis. Because someone in the organisation has left one open it won't work. Therefore I want to exclude that single file (let's call it "Obstacle.xls") so that the macro will delete all the other xl files within the parent folder and subfolders. Can't figure out the syntax though..
Thanks.
[VBA]Sub DeleteAllXLSFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = "\\Parent directory\"
.SearchSubFolders = True
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count ' Loop through all.
fs.DeleteFile .FoundFiles(lCount)
Next lCount
End If
End With
End Sub[/VBA]