Close all without saving and exit without prompts


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?
 
Ad

Advertisements

C

Claus Busch

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.
 
C

Colin Hayes

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
 
C

Claus Busch

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.
 
G

GS

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
 
G

GS

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
 
Ad

Advertisements

C

Claus Busch

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.
 
C

Claus Busch

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.
 
Ad

Advertisements

C

Colin Hayes

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top