tags:

views:

307

answers:

3

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?

+1  A: 

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);
astander
The dialog now doesn't pop up. But no, the application doesn't save the file.
elr
I try to do it like you.. but there is an exception:HRESULT : 0x800A03EC
elr
+1  A: 

Couldn't you try to delete the file first, before overwriting it?

Amigable Clark Kant
If there isn't any other way.. I will choose this.
elr
+1  A: 

There is a property within the SaveFileDialog class, called OverwritePrompt, set that to false.

Hope this helps, Best regards, Tom.

tommieb75
I don't use a SaveFileDialog. I close my excel application.
elr
@elr: Ahhh... You should have said that in the question...and I run the risk of getting downvoted now as a result....are you using Excel COM Interop? Put that in your question also!
tommieb75