ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Button to close without saving (https://www.excelbanter.com/excel-programming/291212-button-close-without-saving.html)

Newbie1

Button to close without saving
 
Hello

I am trying to create code for a commandbutton on a userform which will
close the workbook without saving.

Using <Application.quit throws up a message box giving the user a choice
(which I do not want!)

Is there something similar to <ThisWorkbook.Save (but obviously does not
save!)

Thanks

Kenny






Chip Pearson

Button to close without saving
 
Kenny,

Use something like

ThisWorkbook.Close SaveChanges:=False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Newbie1" wrote in message
...
Hello

I am trying to create code for a commandbutton on a userform

which will
close the workbook without saving.

Using <Application.quit throws up a message box giving the

user a choice
(which I do not want!)

Is there something similar to <ThisWorkbook.Save (but

obviously does not
save!)

Thanks

Kenny








Newbie1

Button to close without saving
 
Hello Chip

Still not quite what I wanted!

I used
Private Sub CommandButton3_Click()

ThisWorkbook.Close SaveChanges:=False
Application.Quit
End Sub

However the file closed but left the Excel menu bar on the screen which I
had to close manually.

When I use:- (on another button)

Sub ChooseNo()
Unload UserForm2
ThisWorkbook.Save
Application.Quit
End Sub

Excel closes completely - This is what I am trying to achieve -
any ideas what I am doing wrong?

Kenny

"Chip Pearson" wrote in message
...
Kenny,

Use something like

ThisWorkbook.Close SaveChanges:=False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Newbie1" wrote in message
...
Hello

I am trying to create code for a commandbutton on a userform

which will
close the workbook without saving.

Using <Application.quit throws up a message box giving the

user a choice
(which I do not want!)

Is there something similar to <ThisWorkbook.Save (but

obviously does not
save!)

Thanks

Kenny










Tom Ogilvy

Button to close without saving
 
When the workbook closes, the code stops, so you never hit quit

In your second example, you don't close the workbook, you just save it.

try this


Private Sub CommandButton3_Click()

ThisWorkbook.Saved=True
Application.Quit
End Sub

Setting Saved = True should tell Excel the workbook does not need to be
saved and it should close without prompting.

--
Regards,
Tom Ogilvy


"Newbie1" wrote in message
...
Hello Chip

Still not quite what I wanted!

I used
Private Sub CommandButton3_Click()

ThisWorkbook.Close SaveChanges:=False
Application.Quit
End Sub

However the file closed but left the Excel menu bar on the screen which I
had to close manually.

When I use:- (on another button)

Sub ChooseNo()
Unload UserForm2
ThisWorkbook.Save
Application.Quit
End Sub

Excel closes completely - This is what I am trying to achieve -
any ideas what I am doing wrong?

Kenny

"Chip Pearson" wrote in message
...
Kenny,

Use something like

ThisWorkbook.Close SaveChanges:=False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Newbie1" wrote in message
...
Hello

I am trying to create code for a commandbutton on a userform

which will
close the workbook without saving.

Using <Application.quit throws up a message box giving the

user a choice
(which I do not want!)

Is there something similar to <ThisWorkbook.Save (but

obviously does not
save!)

Thanks

Kenny












Newbie1

Button to close without saving
 
Tom

Exactly what I wanted - Thanks

Kenny (Newbie1)

"Tom Ogilvy" wrote in message
...
When the workbook closes, the code stops, so you never hit quit

In your second example, you don't close the workbook, you just save it.

try this


Private Sub CommandButton3_Click()

ThisWorkbook.Saved=True
Application.Quit
End Sub

Setting Saved = True should tell Excel the workbook does not need to be
saved and it should close without prompting.

--
Regards,
Tom Ogilvy


"Newbie1" wrote in message
...
Hello Chip

Still not quite what I wanted!

I used
Private Sub CommandButton3_Click()

ThisWorkbook.Close SaveChanges:=False
Application.Quit
End Sub

However the file closed but left the Excel menu bar on the screen which

I
had to close manually.

When I use:- (on another button)

Sub ChooseNo()
Unload UserForm2
ThisWorkbook.Save
Application.Quit
End Sub

Excel closes completely - This is what I am trying to achieve -
any ideas what I am doing wrong?

Kenny

"Chip Pearson" wrote in message
...
Kenny,

Use something like

ThisWorkbook.Close SaveChanges:=False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Newbie1" wrote in message
...
Hello

I am trying to create code for a commandbutton on a userform
which will
close the workbook without saving.

Using <Application.quit throws up a message box giving the
user a choice
(which I do not want!)

Is there something similar to <ThisWorkbook.Save (but
obviously does not
save!)

Thanks

Kenny















All times are GMT +1. The time now is 05:23 PM.

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