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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overwrite existing excel file 1

Status
Not open for further replies.

thesewerguy

Technical User
Jul 5, 2002
4
0
0
US
I'm trying to open excel file from one folder, edit excel file and save it to another folder under a different name. All works well but if a file with that name exists in the destination folder excel pops up with a "file already exists...do you want to overwrite it..bla bla". I thought that having safety set to off would correct the issue but it doesn't. Any ideas on how to prevent warning if the file already exists in the folder?

Thanks
 
If you're using automation to drive Excel from VFP then it's Excel saving the file, not VFP, which is why SET SAFETY has no bearing on the matter. What you probably want to do is write some VFP code to detect if the destination file already exists and if so then to delete it before telling Excel to save the new one of the same name. From a technical POV this is easy to do, but from a design POV it may be questionble whether it's a good idea to go about deleting files on a user's machine without giving them a say-so in the matter.

-Rick
 
As Rick says above, if you are using Excel Automation you will need to use Excel commands....

Something like
Code:
tmpsheet = CREATEOBJECT('excel.Application')
oExcel = tmpsheet.APPLICATION

< Do Whatever... >

* --- Save Excel Results ---
oExcel.CutCopyMode = .F. && Clear the clipboard
oExcel.DisplayAlerts = .F.

* --- Save Results Again ---
xlSheet.SAVEAS(mcExclFName)  && Fully Pathed Excel File Name

* --- Close the Worksheet ---
oExcel.Workbooks.CLOSE

* --- Quit Excel ---
oExcel.QUIT

Good Luck,
JRB-Bldr
 
Thanks everyone for the input. I realized the same thing Rick was pointing out after a short break, Excel is doing the saving and thus must be tackled within Excel. The DisplayAlerts is what I needed to suppress the warning, thx JRB-Bldr.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top