Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help deleting a file from within VB6.

Status
Not open for further replies.

elmorro

Programmer
Jun 23, 2005
133
US
I have an excel file that I need to delete when my program is ran. I tried using the following code:
Kill "C:\ExcelFile.xls"
but it did not work.

How can I accomplish this.

Thanks in advance,
elmorro :)
 
Usually you want
Code:
FN = "C:\ExcelFile.xls"

If Dir(FN) <> "" Then Kill FN
"Kill" will raise an error if you attempt to use it on a file that doesn't exist.
 
HughLerwill,

I kept getting an access denied error. But I change file path and it works now.

Thanks.
 
Golom,
Thanks for the code.
I am also using the following code to save the file:
objWorkBook.SaveAs "C:\ExcelFile.xls"

But if the file is an existant file it pops the following message:
The file already exists, would you like to replace it?

Is there anyway to stop this message from appearing?

Thanks in advance,
elmorro :)
 
Just use Golom's code before your code:

Code:
FN = "C:\ExcelFile.xls"
If Dir(FN) <> "" Then Kill FN
objWorkBook.SaveAs FN

Swi
 
Thanks Swi,

I will do as you suggested.

elmorro :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top