Deleting a file using VB

R

Rohit Thomas

Hello All,

I have delimted text files that I import into Excel using
macros. Once the import is finished, I would like to
delete the text file because it contains SS#'s and other
sensitive info. How do I delete the file from Excel using
VB? The text files are normally located on a LAN.

Thanks in advance,
Rohit Thomas
 
T

Tom Ogilvy

Kill "X:\Myfiles\*.txt"

Anyway, look at the Kill command - after the files are closed.

Kill doesn't put files in the recycle bin. It deletes them and they are
gone - so test, then use carefully.

Regards,
Tom Ogilvy
 
E

Eric W.

Rohit,
This is a modified bit of code that should work. It
assumes that all of the files that will be deleted are in
the same directory, and that there are no other files in
that directory. Hope this helps!!

Eric W.
Madison, WI

Sub Delete_Files()

'Dimension your variables
Dim sFolder
Dim myFolderObject, myGetFolder, myFile, myFiles
myFolder = "g:\eric\files\"
'set your objects
Set myFolderObject = CreateObject
("Scripting.FileSystemObject")
Set myGetFolder = myFolderObject.GetFolder(myFolder)
Set myFiles = f.Files
'loop through the files in a directory
For Each myFile In myFiles
'Delete the appropriate files
myFile.Delete
Next

End Sub
 

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