Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to exit out of Excel all together

Status
Not open for further replies.

DoctorV3774

Programmer
Oct 12, 2004
33
0
0
US
I have code at the end of a sub to close an active workbook save changes no. Is there any code I can use right after this to exit out if Excel altogether? Application.Quit does not seem to work. Thanks

Here is code at the end of my sub

ActiveWorkbook.Close savechanges:=False
 
Just checking ... is the workbook where the Application.Quit is coded actually the same one that you've closed? If so, you can see the problem about relying on statements in a workbook that is no longer open.

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Application.quit should do it, as long as you don't have any other open workbooks.

You can go around this by entering either

Code:
application.displayalerts = false
application.quit

or

Code:
for each wbook In application.workbooks
    wbook.save
Next w
Application.Quit

...depending on wether you want to save the open wb's or not.



// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
Just remembered how I used to do this, I think there's a property of the workbook object that flags whether Excel thinks a workbook has been saved or not. Try this:

Thisworkbook.Saved=True
Application.Quit



Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
...ehum, that would be

next Wbook

(not "next w")

And Glenn has probably located your problem... use the first code I wrote instead of your activeworkbook.close





// Patrik
______________________________

To the optimist, the glass is half full. To the pessimist, the glass is half empty. To the IT Professional, the glass is twice as big as it needs to be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top