why Excel not is closed?

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

why Excel not is closed?

Post by sal21 »

To the end of my code i need to close Excel...

i use:

....
ActiveWorkbook.Close savechanges:=True

Application.Quit
....

Peraphs i need othe piece of code?

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: why Excel not is closed?

Post by HansV »

Where does this code reside? In the workbook that you're closing?
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: why Excel not is closed?

Post by HansV »

Try this instead:

ActiveWorkbook.Save
Application.Quit
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: why Excel not is closed?

Post by sal21 »

HansV wrote:Try this instead:

ActiveWorkbook.Save
Application.Quit
testd and it work perfect!
Tks

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: why Excel not is closed?

Post by sal21 »

HansV wrote:Try this instead:

ActiveWorkbook.Save
Application.Quit
hummmmm...

now, if i have 2 or more session of Excel opened the code Application.Quit, close all session!!!!
But I need to close only the active sessione vwhere the code is running ...

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: why Excel not is closed?

Post by HansV »

If you want to close only the active workbook, use

ActiveWorkbook.Close SaveChanges:=True
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: why Excel not is closed?

Post by sal21 »

HansV wrote:If you want to close only the active workbook, use

ActiveWorkbook.Close SaveChanges:=True
ok but the current Session of Excel remain active on screen, or not?

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: why Excel not is closed?

Post by HansV »

If you use Application.Quit, the active instance of Excel will close with all workbooks opened in that instance. Other instances of Excel will remain active.

If you use ActiveWorkbook.Close, only the active workbook will close, but the instance of Excel will remain active.

It's up to you to decide what you want.
Best wishes,
Hans