Find File Name and Delete

M

mrsviqt

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.
 
M

mrsviqt

It works. Thanks so much for your help!

PJFry said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top