How to Save/Overwrite existing Excel file with Excel Interop - C#

我怕爱的太早我们不能终老 提交于 2019-11-30 06:17:42

Basically, all you need is ExcelApp.DisplayAlerts = False - Here's how I do it, though:

ExcelApp.DisplayAlerts = False
ExcelWorkbook.Close(SaveChanges:=True, Filename:=CurDir & FileToSave)

Hope this helps

Only this code will Require for stop override alert or Template already in use

ExcelApp.DisplayAlerts = False

I know this is an old post, but I wanted to share a way to make this work without causing possible frustration in the future.

First what I do not like about using: ExcelApp.DisplayAlerts = False

Setting this flag will set this property on the excel file, not just in your program. This means that if a user makes changes to the file and closes it (by clicking the X), they will not be prompted to save the file and will cause frustration later. It will also disable any other prompts excel would typically post.

I like checking if the file exists before saving it:

        if (File.Exists(SaveAsName))
        {
            File.Delete(SaveAsName); 
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!