I have an Excel workbook with a custom non-time-dependent cell function that I am opening from a C# WindowsForms application using Interop.Excel. I read four values from it, perform no explicit changes/calculations, then close it from C#.
When I try to directly close (without saving), I get a save prompt. I suspect this is because Excel is interpreting auto-recalculation on open as creating a change, even though nothing actually numerically or formulaically changes. I also set Excel.Application.Calculation = Excel.XlCalculation.xlCalculationManual
. How do I prevent the save prompt from appearing and just close-without-save?
Press close button while holding Shift key, then press Don't save (still holding Shift ).
You can also use this for closing workbook without saving changes. ~Sub CloseBook2() ActiveWorkbook. Close savechanges:=False End Sub~ This routine can be attached to Close X Button.
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.
Steps to Close a Workbook Specify the workbook that you want to close. Use the close method with that workbook. In the code method, specify if you want to save the file or not. In the end, mention the location path where you want to save the file before closing.
When you use the Excel objects, be sure to close the workbook like this:
Excel.Application xlApp ; Excel.Workbook xlWorkBook ; Excel.Worksheet xlWorkSheet ; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add("Yourworkbook"); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); ....do your stuff xlWorkBook.Close(false, misValue, misValue); xlApp.Quit();
The false in the close method indicates don't save changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With