Close all without saving and exit without prompts

  • Thread starter Thread starter Colin Hayes
  • Start date Start date
C

Colin Hayes

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?
 
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.
 
Claus Busch said:
hi Colin,

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


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
 
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.
 
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
 
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
 
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.
 
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.
 
Claus Busch said:
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
 
Back
Top