VBA: Exit Without Saving

Automate Excel

VBA: Exit Without Saving

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

5 Responses

  1. ross Says:

    but would you want to?????!

  2. Mark Says:

    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. ross Says:

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

  4. Wendell Says:

    This is just what I was looking for.
    Thanks

  5. Brendan Says:

    @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.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.