Thread: loop and delete
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Peterke Peterke is offline
external usenet poster
 
Posts: 16
Default loop and delete

This is my problem:

I want to loop through all the files in a folder, and delete all files that
are not called "ABC_QUALITY_RATE.xls"
I think i'm close, but he's not very happy with the "Kill
..FoundFiles(WegErmee)"...

What am i doing wrong? This is what i have so far:


Sub Test()
Dim Bandiet As Integer

Set fs = Application.FileSearch

Application.ScreenUpdating = False
Application.DisplayAlerts = False



With fs
.NewSearch
.LookIn = "C:\DATA\ABC"

If .Execute 0 Then

For Bandiet = 1 To .FoundFiles.Count

If .Filename < "ABC_QUALITY_RATE.xls" Then

For WegErmee = 1 To .FoundFiles.Count

GoTo Verwijderen

Next WegErmee

End If

Next Bandiet

End If

End With

Verwijderen:

Kill .FoundFiles(WegErmee)

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

Please advise,
Peter