ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Exit without saving in a macro (https://www.excelbanter.com/excel-programming/376043-exit-without-saving-macro.html)

Brian

Exit without saving in a macro
 
I have a macro that closes a worksheet in excel and I want to close it and
not save (usually a box appears asking if I want to save before exiting and I
want to say no in the macro)

Jim Thomlinson

Exit without saving in a macro
 
In the before close event add
ThisWorkbook.Saved = True

This is the flag that Excel uses to determine if the file needs to be saved
and the code above say that the file does not need to be saved. Don't place
any code after this line as that could change the spreadsheet and flip the
flag back again.
--
HTH...

Jim Thomlinson


"Brian" wrote:

I have a macro that closes a worksheet in excel and I want to close it and
not save (usually a box appears asking if I want to save before exiting and I
want to say no in the macro)


Renato M. T.

Exit without saving in a macro
 
Hi Brian,
you can use:

Worksheets("yourworksheets").close Savechanges:= false

This is best way to do it, and never ask you about save changes.



"Brian" escreveu:

I have a macro that closes a worksheet in excel and I want to close it and
not save (usually a box appears asking if I want to save before exiting and I
want to say no in the macro)


Jim Thomlinson

Exit without saving in a macro
 
Your code does not work. Close is not a method of the worksheets object. It
is a method of the workbook. You could use

Thisworkbook.Close SaveChanges:=False

but it requires that the user close the workbook via a command button or
such to execute this line of code. If the user closes the workbook via the x
then this code never executes and the user is prompted about saving...
--
HTH...

Jim Thomlinson


"Renato M. T." wrote:

Hi Brian,
you can use:

Worksheets("yourworksheets").close Savechanges:= false

This is best way to do it, and never ask you about save changes.



"Brian" escreveu:

I have a macro that closes a worksheet in excel and I want to close it and
not save (usually a box appears asking if I want to save before exiting and I
want to say no in the macro)


Dana DeLouis

Exit without saving in a macro
 
I have a macro that closes a worksheet

If it's a worksheet, and not a workbook, perhaps...

Sub Demo()
Application.DisplayAlerts = False
Worksheets(1).Delete
Application.DisplayAlerts = True
End Sub

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"Brian" wrote in message
...
I have a macro that closes a worksheet in excel and I want to close it and
not save (usually a box appears asking if I want to save before exiting
and I
want to say no in the macro)





All times are GMT +1. The time now is 11:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com