Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When trying to close a spreadsheet, Excel asks user whether to save changes

Tags:

c#

excel

epplus

We generate a bunch of reports to Excel spreadsheets using EPPlus.

Typically the code goes something like this:

var workbookFile = new FileInfo(reportFile);
using (var excel = new ExcelPackage(workbookFile))
{
    var wb = excel.Workbook;
    var ws = wb.GetCleanWorksheet("Report");
    ws.Select();

    // write data to sheet
    ws.Cells[1, 1].Value = "foo";

    excel.Save();
}

When the user opens the spreadsheet, everything looks fine. When they try to close the spreadsheet without having made any changes, Excel will ask them whether they want to save their changes. This isn't too big a deal but it's annoying and slightly worrying.

I've opened the spreadsheets in the OpenXML SDK Productivity Tool and they pass validation in that.

like image 934
Coxy Avatar asked Feb 10 '15 04:02

Coxy


People also ask

Why does Excel always ask if I want to save changes?

This behavior occurs when something in the file has changed. Many times the user doesn't realize there are elements in the file that have been updated or calculated. Here are some examples of common scenarios: There is a volatile function used in the file.

How do I turn off Save Changes prompt when I close a workbook in Excel?

Summary. In Microsoft Excel, you can create a Microsoft Visual Basic for Applications (VBA) macro that suppresses the Save Changes prompt when you close a workbook. This can be done either by specifying the state of the workbook Saved property, or by suppressing all alerts for the workbook.

Which one would you click to exit the Excel without saving the changes?

If you click Save and you have previously saved your file, Excel saves your file in the same location you previously saved it, using the file name and file type you previously used. If you click Don't Save, Excel exits without saving. If you click Cancel, Excel returns to the workbook and you can continue editing.


1 Answers

Here's an response to a similar question answered by Microsoft support at http://support.microsoft.com/kb/213428 "To force a workbook to close without saving any changes, type the following code in a Visual Basic module of that workbook:

Sub Auto_Close()

ThisWorkbook.Saved = True

End Sub

Because the Saved property is set to True, Excel responds as though the workbook has already been saved and no changes have occurred since that last save."

Hope that helps.

like image 191
microstat10 Avatar answered Sep 26 '22 01:09

microstat10