MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Macro to exit Excel


Posted by TR on August 11, 2001 12:10 AM

Hope someone can help me here. I have a macro that directs users to a worksheet where they can enter their name and a few details which are then printed out. I need then to exit Excel without saving this workbook so it is ready for the next user. Can anyone tell me how to incorporate the exiting without saving into my macro.
TIA
TR


Posted by Rob Jackson on August 11, 2001 2:43 AM

A couple of options, if you want to simply close the workbook without saving, run this line:

windows("Nameof File.xls").close savechanges:=false

This is One line of Code. it may appear as two on this viewer.

to close excel use

windows.application.quit

Rob

Posted by TR on August 11, 2001 4:32 PM

Thanks Rob on your reply and suggestions. However, still in a bit of bother.
"windows("Nameof File.xls").close savechanges:=false"
works fine but still leaves Exel open.
"windows.application.quit"
works fine also but still brings up a prompt asking if the file wants to be saved.
I tried putting the two lines together in the one macro but of course that didn't work as once the workbook is closed the macro is as well.
Also I tried putting
"savechanges:=false"
at the end of "Quit". All I get then was an error message.
What I have, to give you an idea what I need, is a MS Powerpoint presentation (a workplace induction) with a link on the last screen to an Excel file. This file is simply where the inductee puts his/her name and details on a form which is then printed out for documentary evidence. On completion of that the file is shut down without saving thus not requiring a supervisor to shut it down.
A fairly long winded post but I hope you may further help me in this.
Many t i a
TR

Posted by Paul on August 12, 2001 3:42 PM

Sub macrorequired()

ActiveWorkbook.Saved = True ' cancels any changes

Windows.Application.Quit ' closes wkbk & excel

End Sub

This should work if you only have the one workbook open.