Jan 12, 2007 #1 elmorro Programmer Joined Jun 23, 2005 Messages 133 Location 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
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
Jan 12, 2007 #2 HughLerwill Programmer Joined Nov 22, 2004 Messages 1,818 Location GB Did you get an error message; if so what was it? Upvote 0 Downvote
Jan 12, 2007 #3 Golom Programmer Joined Sep 1, 2003 Messages 5,595 Location CA 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. Upvote 0 Downvote
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.
Jan 12, 2007 Thread starter #4 elmorro Programmer Joined Jun 23, 2005 Messages 133 Location US HughLerwill, I kept getting an access denied error. But I change file path and it works now. Thanks. Upvote 0 Downvote
Jan 12, 2007 Thread starter #5 elmorro Programmer Joined Jun 23, 2005 Messages 133 Location US 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 Upvote 0 Downvote
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
Jan 12, 2007 #6 Swi Programmer Joined Feb 4, 2002 Messages 1,978 Location US Just use Golom's code before your code: Code: FN = "C:\ExcelFile.xls" If Dir(FN) <> "" Then Kill FN objWorkBook.SaveAs FN Swi Upvote 0 Downvote
Just use Golom's code before your code: Code: FN = "C:\ExcelFile.xls" If Dir(FN) <> "" Then Kill FN objWorkBook.SaveAs FN Swi
Jan 15, 2007 Thread starter #7 elmorro Programmer Joined Jun 23, 2005 Messages 133 Location US Thanks Swi, I will do as you suggested. elmorro Upvote 0 Downvote