Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default loop and delete

That's because .FoundFiles should be within the with statement. Right
now it falls outside and Mr. VBA gets confused. Change it to:


Next Bandiet
End If
Verwijderen:
Kill .FoundFiles(WegErmee)
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default loop and delete

If using FileSearch, I would modify your code like this.

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 .FoundFiles(Bandiet) < "C:\DATA\ABC" & _
Application.PathSeparator & "ABC_QUALITY_RATE.xls" Then
Kill .FoundFiles(Bandiet)
End If
Next Bandiet
End If
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

keizi

"Peterke" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default loop and delete

Thanks Kletcho!
That was the trick that did it! But now i've encountered another problem:
The files that have to be deleted have no extension == "Mr. Vba" does
not recognize it as a "File". What can i do about that?

Regards,
Peter
"Kletcho" schreef in bericht
oups.com...
That's because .FoundFiles should be within the with statement. Right
now it falls outside and Mr. VBA gets confused. Change it to:


Next Bandiet
End If
Verwijderen:
Kill .FoundFiles(WegErmee)
End With



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop & Delete Jenna Excel Discussion (Misc queries) 3 January 24th 07 06:34 PM
How to Delete Rows in Excel In a Do Loop indraneel Excel Worksheet Functions 6 September 15th 06 09:51 AM
A loop to delete Nikki Excel Programming 1 December 3rd 04 07:59 PM
loop to delete rows... Froglegz Excel Programming 5 August 1st 04 09:56 PM
How do I delete rows and columns in With With End Loop? Bob Benjamin Excel Programming 3 November 16th 03 12:26 AM


All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"