1

i'm saving a bunch of calculated data into an excel file using

if (result == DialogResult.OK && saveFileDialog1.FileName != "")
        {
            xl.DisplayAlerts = false;
            wb.SaveAs(fn, XlFileFormat.xlOpenXMLWorkbook, Missing.Value,
            Missing.Value, false, false, XlSaveAsAccessMode.xlNoChange,
            XlSaveConflictResolution.xlUserResolution, true,
            Missing.Value, Missing.Value, Missing.Value);

            wb.Close(true, misValue, misValue);
            xl.Quit();

            releaseObject(ws);
            releaseObject(wb);
            releaseObject(xl);
        }
        else if (result == DialogResult.Cancel)
        {
            wb.Close(true, misValue, misValue);
            xl.Quit();
            releaseObject(ws);
            releaseObject(wb);
            releaseObject(xl);
        }

everything is working fine when i press OK, but if i CANCEL the save, then another "generic" save window shows up? I have no other SaveFileDialogs in the project, my assumption is that it comes from the Excel object save file dialog, but i really don't know how can i get rid of this?

xl is the interop object, ws the worksheet and wb the workbook

TA

ferday
  • 197
  • 4
  • 13
  • Possible duplicate of [Excel interop: saving workbook without showing save dialog](http://stackoverflow.com/questions/7012705/excel-interop-saving-workbook-without-showing-save-dialog) – Nino Mar 16 '17 at 10:24
  • 1
    not a duplicate! i want the save dialog, just not the second save dialog. that thread is about workbook.SaveAs (which i'm already using). Thanks for the research though! – ferday Mar 16 '17 at 11:09

1 Answers1

4

Set 'Saved' property of workbook's object to true before calling Close method.

Like so:

else if (result == DialogResult.Cancel)
        {
            wb.Saved = true;
            wb.Close(true, misValue, misValue);
            xl.Quit();
            releaseObject(ws);
            releaseObject(wb);
            releaseObject(xl);
        }

Hope this would help.

Azaz ul Haq
  • 1,635
  • 2
  • 18
  • 46