PC Review


Reply
Thread Tools Rate Thread

How to close ALL instances of Excel

 
 
spIky haIred
Guest
Posts: n/a
 
      11th Oct 2006
Hi everyone,

I would like to close ALL instances of Excel... I am able to close all
workbooks within an instance of Excel but cannot close workbooks in
other instances of Excel... Is there a way to scan all open windows? Or
even better, to scan all open instances of Excel only?

Help would be much appreciated.
Thanks in advance,
Jason

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      11th Oct 2006
This code is to run in Excel VBA ?
You want to close your own instance ?

Depending on the above GetObject may not be the answer, as you cannot
stipulate which instance gets returned.
Maybe use the API FindWindow with "XLMAIN" and SendMesssage with "WM_CLOSE"
?

NickHK

"spIky haIred" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi everyone,
>
> I would like to close ALL instances of Excel... I am able to close all
> workbooks within an instance of Excel but cannot close workbooks in
> other instances of Excel... Is there a way to scan all open windows? Or
> even better, to scan all open instances of Excel only?
>
> Help would be much appreciated.
> Thanks in advance,
> Jason
>



 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      11th Oct 2006
Sorry, that should be PostMessage not SendMessage.
http://support.microsoft.com/?kbid=176391
http://vb-helper.com/howto_terminate_process.html

But you would still need to check if the Excel instance is yours, if running
in Excel/VBA.

NickHK

"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This code is to run in Excel VBA ?
> You want to close your own instance ?
>
> Depending on the above GetObject may not be the answer, as you cannot
> stipulate which instance gets returned.
> Maybe use the API FindWindow with "XLMAIN" and SendMesssage with

"WM_CLOSE"
> ?
>
> NickHK
>
> "spIky haIred" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi everyone,
> >
> > I would like to close ALL instances of Excel... I am able to close all
> > workbooks within an instance of Excel but cannot close workbooks in
> > other instances of Excel... Is there a way to scan all open windows? Or
> > even better, to scan all open instances of Excel only?
> >
> > Help would be much appreciated.
> > Thanks in advance,
> > Jason
> >

>
>



 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      11th Oct 2006
Application.Quit is one way, but you might get a few dialog boxes to respond
to if you don't either save the workbooks or mark them as saved before you
apply it.

"NickHK" wrote:

> Sorry, that should be PostMessage not SendMessage.
> http://support.microsoft.com/?kbid=176391
> http://vb-helper.com/howto_terminate_process.html
>
> But you would still need to check if the Excel instance is yours, if running
> in Excel/VBA.
>
> NickHK
>
> "NickHK" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > This code is to run in Excel VBA ?
> > You want to close your own instance ?
> >
> > Depending on the above GetObject may not be the answer, as you cannot
> > stipulate which instance gets returned.
> > Maybe use the API FindWindow with "XLMAIN" and SendMesssage with

> "WM_CLOSE"
> > ?
> >
> > NickHK
> >
> > "spIky haIred" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi everyone,
> > >
> > > I would like to close ALL instances of Excel... I am able to close all
> > > workbooks within an instance of Excel but cannot close workbooks in
> > > other instances of Excel... Is there a way to scan all open windows? Or
> > > even better, to scan all open instances of Excel only?
> > >
> > > Help would be much appreciated.
> > > Thanks in advance,
> > > Jason
> > >

> >
> >

>
>
>

 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      11th Oct 2006
hi all, thanks for your help on this, i have tried application.quit but
it still leaves the other "instances" of excel open...
Nick i shall try your solutions, thanks again

 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      12th Oct 2006
sorry guys, couldnt get the solutions to work...
any more advice?
let me rephrase my question... probably wasn't clear at the start..
im trying to close all excel workbooks in any number of windows using
either excel vba or vbscript...
thanks again

 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      12th Oct 2006
sorry guys, couldnt get the solutions to work...
any more advice?
let me rephrase my question... probably wasn't clear at the start..
im trying to close all excel workbooks in any number of windows using
either excel vba or vbscript...
thanks again

 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      12th Oct 2006
sorry guys, couldnt get the solutions to work...
any more advice?
let me rephrase my question... probably wasn't clear at the start..
im trying to close all excel workbooks in any number of windows using
either excel vba or vbscript...
thanks again

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      12th Oct 2006
So you are closing Workbooks in the same (your current) instance of Excel ?
Dim WB As Workbook
For each wb in workbooks
if wb.name<>thisworkbook.name then
wb.close 'True/false depending on your requirements
end if
next

VBScript would be the same, but with an added
Dim XLAPP as object
Dim WB As Workbook

set xlapp=getobject("Excel.Application")
if not xlapp is nothing then
For each wb in xlapp.workbooks
wb.close 'True/false depending on your requirements
next
end if

Clossing all WBs in all instances from VBScript
Dim XLAPP as object
Dim WB As Workbook

do
set xlapp=getobject("Excel.Application")
if xlapp is nothing then exit sub
For each wb in xlapp.workbooks
wb.close 'True/false depending on your requirements
next
loop

You should add error handling

NickHK

"spIky haIred" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> sorry guys, couldnt get the solutions to work...
> any more advice?
> let me rephrase my question... probably wasn't clear at the start..
> im trying to close all excel workbooks in any number of windows using
> either excel vba or vbscript...
> thanks again
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close all Instances of Excel Alan Microsoft Access VBA Modules 1 30th Aug 2009 02:24 AM
Close all Instances of Excel Alan Microsoft Access VBA Modules 4 18th Aug 2009 06:53 PM
I can't save a file unless I close all excel instances or it's th. =?Utf-8?B?QlZCT1dFUw==?= Microsoft Excel Misc 0 26th Apr 2005 09:20 PM
Close all Instances of Excel Tod Microsoft Excel Programming 9 22nd Feb 2005 04:05 PM
Excel Instances don't close =?Utf-8?B?SWFuVw==?= Microsoft Dot NET 6 28th Apr 2004 10:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.