rakete rakete - 3 months ago 15
Vb.net Question

How can I overwrite an other Excel-file without the Dialog "Really want to overwrite" in VB.NET

How can I save an Excel-file, which I'd edit with VB.NE, to a file, which already exists? Evertime there is a dialog: File already exists. Do you really want to overwrite? YES|NO|Abort

How can I overwrite without this dialog?

Answer

You should have a look at setting

DisplayAlerts=false

Application.DisplayAlerts Property

Set this property to False if you don’t want to be disturbed by prompts and alert messages while a program is running; any time a message requires a response, Microsoft Excel chooses the default response.

Just remember to reset it to true once you are done.

We currently do it as follows

object m_objOpt = Missing.Value;
m_Workbook.Application.DisplayAlerts = false;
m_Workbook.SaveAs(  fileName, m_objOpt, m_objOpt, 
                    m_objOpt, m_objOpt, m_objOpt, 
                    XlSaveAsAccessMode.xlNoChange, 
                    XlSaveConflictResolution.xlLocalSessionChanges, 
                    m_objOpt, m_objOpt, m_objOpt, m_objOpt);