ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Close all without saving and exit without prompts (https://www.excelbanter.com/excel-worksheet-functions/449508-close-all-without-saving-exit-without-prompts.html)

Colin Hayes

Close all without saving and exit without prompts
 


HI All

I'm trying to find a macro to close all open worksheets without saving
and exit Excel without prompts.

When I run the macro , Excel just closes with no popups of any kind. No
worksheets need to be saved.

Can someone help?



Claus Busch

Close all without saving and exit without prompts
 
hi Colin,

Am Sun, 17 Nov 2013 14:50:16 +0000 schrieb Colin Hayes:

I'm trying to find a macro to close all open worksheets without saving
and exit Excel without prompts.


try:

Sub Test()
Dim wbk As Workbook

For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close savechanges:=False
End If
Next
With Application
.DisplayAlerts = False
.Quit
.DisplayAlerts = True
End With
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

Colin Hayes

Close all without saving and exit without prompts
 
In article , Claus Busch
writes
hi Colin,

Am Sun, 17 Nov 2013 14:50:16 +0000 schrieb Colin Hayes:

I'm trying to find a macro to close all open worksheets without saving
and exit Excel without prompts.


try:

Sub Test()
Dim wbk As Workbook

For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close savechanges:=False
End If
Next
With Application
.DisplayAlerts = False
.Quit
.DisplayAlerts = True
End With
End Sub


Regards
Claus B.


Hi Claus

OK thanks for this and again for your help.

I find it works fine for worksheets opened after the initial opening
sheet (book1), but still give prompts where any change in book1 or it's
macros has been made.

Worksheets opened and changed after this are close without prompt ,
which is correct.

What do you think?


Best Wishes


Colin



Claus Busch

Close all without saving and exit without prompts
 
Hi Colin,

Am Sun, 17 Nov 2013 17:15:56 +0000 schrieb Colin Hayes:

I find it works fine for worksheets opened after the initial opening
sheet (book1), but still give prompts where any change in book1 or it's
macros has been made.


and you also don't want to save book1?


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

GS[_2_]

Close all without saving and exit without prompts
 
I'm inclined to go with this modified version of Claus' offering...

Sub Test()
Dim wkb As Workbook

For Each wbk In Workbooks
If wkb.Visible And wkb < ThisWorkbook Then _
wkb.Close SaveChanges:=False
Next
With Application
.DisplayAlerts = False: .Quit: .DisplayAlerts = True
End With
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


GS[_2_]

Close all without saving and exit without prompts
 
Typo...

I'm inclined to go with this modified version of Claus' offering...

Sub Test()
Dim wkb As Workbook

For Each wkb In Workbooks
If wkb.Visible And wkb < ThisWorkbook Then _
wkb.Close SaveChanges:=False
Next
With Application
.DisplayAlerts = False: .Quit: .DisplayAlerts = True
End With
End Sub


--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


Claus Busch

Close all without saving and exit without prompts
 
Hi Colin,

Am Sun, 17 Nov 2013 17:15:56 +0000 schrieb Colin Hayes:

I find it works fine for worksheets opened after the initial opening
sheet (book1), but still give prompts where any change in book1 or it's
macros has been made.


then try:

Sub Test()
Dim wbk As Workbook

For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close savechanges:=False
End If
Next
ThisWorkbook.Saved = True
Application.Quit
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

Claus Busch

Close all without saving and exit without prompts
 
Hi Garry,

Am Sun, 17 Nov 2013 12:46:49 -0500 schrieb GS:

.DisplayAlerts = False: .Quit: .DisplayAlerts = True


still you set DisplayAlerts to false with Quit the prompt is shown.
Only solution is ThisWorkbook.Saved=True


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

Colin Hayes

Close all without saving and exit without prompts
 
In article , Claus Busch
writes
Hi Colin,

Sub Test()
Dim wbk As Workbook

For Each wbk In Workbooks
If wbk.Name < ThisWorkbook.Name Then
wbk.Close savechanges:=False
End If
Next
ThisWorkbook.Saved = True
Application.Quit
End Sub


Regards
Claus B.



HI Guys

OK thanks for this. All working fine now.

Everything closes with no saving and no prompts at all. Perfect.


^_^



Best Wishes


Colin


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

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