mtrussell
asked on
Deleting a file from a folder using VBA
This question is probably pretty straight forward but given the consequences if I get it wrong I thought I would ask.
I have a table that has the name of all the files in a particular folder on my c: drive. If I delete it out of the table I want it to delete the file out of the folder too. I have the functionality to import the file names and to delete the file name out of the table I need to delete the file now out of the folder.
How would I do this. I get once the file is deleted it is gone, so that is why I am asking.
I have a table that has the name of all the files in a particular folder on my c: drive. If I delete it out of the table I want it to delete the file out of the folder too. I have the functionality to import the file names and to delete the file name out of the table I need to delete the file now out of the folder.
How would I do this. I get once the file is deleted it is gone, so that is why I am asking.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No points for this, please :)
You can run Jeff's code above without setting a reference by changing:
Dim fso As FileSystemObject
to
Dim fso As Object
Patrick
You can run Jeff's code above without setting a reference by changing:
Dim fso As FileSystemObject
to
Dim fso As Object
Patrick
Hi Patrick: I have to ask: "Why would you want to?" It has aspects of using a table saw without a guard ;-)
Ray,
1) Laziness :)
2) Not really applicable for the Scripting Runtime library, but I try to do most of my external references using late binding so as to keep maximum flexibility if there may be a range of versions in use
Patrick
1) Laziness :)
2) Not really applicable for the Scripting Runtime library, but I try to do most of my external references using late binding so as to keep maximum flexibility if there may be a range of versions in use
Patrick
ASKER
thanks
<...range of versions in use> - Thanks, completely overlooked that.
In this case you will have load a reference to the Windows Scripting Runtime Library in your VBA editor and use code like this:
Dim fso As FileSystemObject
Set fso = CreateObject("Scripting.Fi
fso.DeleteFile ("C:\YourFolder\YourFile.x
JeffCoachman