overwriting an existing Excel file

jerryfchui
07-09-2001, 09:32 PM
I've success in creating and saving a new Excel workbook using VBA codes.

But when the system detects a file with the same name it always pops up a warning message from Excel, prompting the user whether to overwrite the file or not. I don't want that. I simply want it to overwrite without warning. This gives me some headache.

I'd tried the Excel workbook method wrkbookx.saveAs("filename", True) and I am aware of setting the property called "AlertBeforeOverwriting" of an Excel Application object to False. Neither works.

Who has this experience? Some short sample codes will help.

junice
07-09-2001, 10:33 PM
what you can do is to check for the existence of the file first, and delete it, before creating the new excel file.

if dir("filename") <> "" then
kill("filename")
end if

the statement kill() will delete the file specified.

pratim_g
07-10-2001, 04:43 AM
I also agree with what soln. was given. You can first check if the specific file exists and then delete it and later over write it with the new file with the FileCopy(old,new) method.
Try this and let me know...
Pratim

jerryfchui
07-10-2001, 05:06 PM
Honest speaking, I realise the suggested workaround before putting up my question and I knew they work.

I am seeking an answer from "academic" viewpoint. I couldn't always inform my student to work around when I could not explain something.

I still wonder what I did wrong when those statements (wrkbookx.saveAs, or "AlertBeforeOverwriting") I used did not work.

Thanks a lot for all replies.

jerryfchui
07-17-2001, 05:59 PM
I found the "Excel answer". This is by setting the DisplayAlerts property to false. This works as long as the file being overwritten was not read-only.

I've got the hint after reading a different question posted a few days after this one. The person there has the answer but misses this post.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum