VBA: Exit Without Saving

October 22nd, 2004 | Categories: VBA | Tags:

exitYou can exit or close Excel without asking the user to save by setting display alerts to False and calling Application.Quit. Here’s some simple example code to exit Excel without prompting the user to save:

Sub ExitWithoutPrompt()
     Application.DisplayAlerts = False
     Application.Quit
End Sub
  1. October 24th, 2004 at 14:47
    Reply | Quote | #1

    but would you want to?????!

  2. Mark
    October 26th, 2004 at 08:38
    Reply | Quote | #2

    Most of the time I post whatever comes to mind or from notes, however sometimes I post relating to people searching this site for topics I haven’t covered, this is the case with this post.

    I can’t think of many practical reasons for doing this however – possibly a calculator template that a user can manipulate but should exit without saving the current state?

  3. December 15th, 2004 at 10:53
    Reply | Quote | #3

    maybe – sounds like trouble to me though! – even if you’ve cerated a new instance of the excel object

  4. Wendell
    November 12th, 2008 at 21:54
    Reply | Quote | #4

    This is just what I was looking for.
    Thanks

  5. Brendan
    December 4th, 2008 at 01:41
    Reply | Quote | #5

    @ross, mark.

    Might not be particularly useful in general Excel use, but has a fantastic use in programming Excel from other applications using COM automation.

    appExcel.DisplayAlerts = False
    appExcel.Quit

    Inside the exception procedure if something else gets ballsed up. This prevents having a hundred EXCEL.EXE processes in the background while you’re debugging, because every “New Excel.Application” spawns a new Excel process.

  6. Monit
    May 15th, 2009 at 05:56
    Reply | Quote | #6

    Worked for me… thanks

  7. Keith Bricknell
    June 24th, 2009 at 14:10
    Reply | Quote | #7

    Set up a scheduled task to open excel, query an sql database, create a new (non-query) workbook with the results. Attached the new workbook to an email and sent it.

    works a treat, the only bit I was missing was displayalerts = false!

    thanks!!!!