I am trying to use the Excel 2013 com interface to use the SaveAs function. Everything is working pretty well except that every SaveAs operation will overwrite the existing file.
Related Questions:
Why can't I “save as” an Excel file from my Python code?
This is how I instantiate Excel:
import win32com.client
excel = win32com.client.gencache.EnsureDispatch('Excel.Application')
excel.Visible = 1
wb = excel.Workbooks.Open('D:\\somefileXYZ.xls')
excel.DisplayAlerts = False
The file 'D:\somefile.xls' already exists.
Using the Microsoft reference it should work like this:
wb.SaveAs('D:\\test.xls', win32com.client.constants.xlWorkbookNormal, \
None, None, False, False, win32com.client.constants.xlNoChange, \
win32com.client.constants.xlOtherSessionChanges)
but it just overwrites the existing file.
Using this it should throw an exception, but this also just overwrites the existing file.
wb.SaveAs('D:\\test.xls')
If I remove this line excel.DisplayAlerts = False
Excel asked me if I want to overwrite the existing file. But I want to do it automatically.
I did the same at another computer with Excel 2007 and everything was working fine.