View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Gary Brown[_5_] Gary Brown[_5_] is offline
external usenet poster
 
Posts: 236
Default How to delete multiple files?

Your code works perfectly for me.
Try..
If UCase(Cells(i, 1).Value) = "X" Then

so that if you use a capital or small 'x', it'll still work.

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Adnan" wrote:

Correct, the myFName includes the whole path of the file (i.e.:
C:\Temp\MyFile.xls). What it is, is a list of file paths that I extracted
from a folder with subfolders, these paths are from B3 and downwards, I had
to have the loop going thru them and deleting the once marked with an X in
column A.

Thanks for your quick response Gary,
Adnan



"Gary Brown" wrote:

I'm guessing that your mFName does not include the folder.
To work, the kill method should include the entire path and name to
guarantee that the KILL statement can find the correct file.

ie: Kill C:\Temp\MyFile.xls
instead of
Kill MyFile.xls
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Adnan" wrote:

Hi to all,

Could anyone please tell me as to why the following code won't work?


Sub LargoFiles()

Dim lRow As Long
Dim i As Long
Dim myFName As String

With ActiveSheet
lRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

On Error Resume Next

For i = 3 To lRow
If Cells(i, 1).Value = "x" Then
myFName = Cells(i, 2).Value
Kill myFName ' delete files specified with an x
RmDir Cells(i, 1).Value 'delete the folder also
if it's empty
Cells(i, 1).Value = "Deleted" 'mark row as deleted
End If
Next i

On Error GoTo 0

End Sub



Would appreciate any help provided,
Adnan