ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find File Name and Delete (https://www.excelbanter.com/excel-programming/427681-re-find-file-name-delete.html)

PJFry

Find File Name and Delete
 
I scratched this out.

Sub KillFiles()

Dim fPath As Range
Dim fName As Range
Dim fDelete As Range

Set fPath = Sheet1.Range("A2")
Set fName = fPath.Offset(0, 1)
Set fDelete = fPath.Offset(0, 2)

Do Until IsEmpty(fPath)

If Dir(fPath & "\" & fName) < "" And fDelete = "Yes" Then
Kill fPath & "\" & fName

Set fPath = fPath.Offset(1, 0)
Set fName = fName.Offset(1, 0)
Set fDelete = fDelete.Offset(1, 0)
Else
Set fPath = fPath.Offset(1, 0)
Set fName = fName.Offset(1, 0)
Set fDelete = fDelete.Offset(1, 0)
End If

Loop

End Sub

I'd test it on a sample file and directory first.
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.



"mrsviqt" wrote:

I have an excel document that has two columns: A=Folder/Path, B=Filename. I
plan to add a yes/no validation list to column C. I need to write a macro so
that if column C = Yes, Go to Folder/Path/Filename and delete that file. Is
that even possible? Any help is greatly appreciated. I have about 10,000
files that need to be deleted.



All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com