How to exit the application without saving the document


As a developer you may want the ability to exit ArcMap without being prompted to the save the current document. Also when you create a new document or open a different document, you might not want to be prompted to save the previous document.

Option 1

You can use the Visual Basic SendKeys statement to dismiss the Save changes to document dialog when ArcMap is shutdown or when a document is closed. The SendKeys statement sends one or more keystrokes to the active window as if typed at the keyboard.
If you want to shutdown ArcMap programmatically without showing the Save dialog, use the Shutdown method on IApplication followed by SendKeys "n". "n" specifies "no" in the Save dialog.
 
If you want to just ignore the Save dialog when a new document is created, when a different document is opened, or when a user manually exits ArcMap, you can write code in the MxDocument_BeforeCloseDocument event. Simply add SendKeys "n" to the code for this event.

Option 2

There is an interface called IDocumentDirty2 that allows you to set the document's dirty flag to False. If the document's dirty flag is set to True, then you will be prompted to save the document when the document is closed or the ArcMap application is shutdown.
 
If you want to shutdown ArcMap programmatically without showing the Save dialog, call the SetClean method on IDocumentDirty2 and then call the Shutdown method on IApplication.
If you want to just ignore the Save dialog when a new document is created, when a different document is opened, or when a user manually exits ArcMap, you can write code in the MxDocument_BeforeCloseDocument event. Simply call the SetClean method on IDocumentDirty2.

How to use

  1. Paste this code into the Project ThisDocument code window in the Visual Basic Editor in ArcMap.
  2. Run the ExitApp macro to exit the application now without saving the document.
[VBA]
' Option 1: Programmatically exit ArcMap

Public Sub ExitApp()
    Application.Shutdown
    SendKeys "n"
End Sub


' Option1: Dismiss the Save dialog when a new document is created,
' when a different document is opened, or when a user manually exits ArcMap

Private Function MxDocument_BeforeCloseDocument() As Boolean
    SendKeys "n"
End Function


' Option 2: Programmatically exit ArcMap

Public Sub ExitApp2()
    Dim pDocDirty As IDocumentDirty2
    Set pDocDirty = Application.Document
    pDocDirty.SetClean
    Application.Shutdown
End Sub


' Option 2: Dismiss the Save dialog when a new document is created,
' when a different document is opened, or when a user manually exits ArcMap

Private Function MxDocument_BeforeCloseDocument() As Boolean
    Dim pDocDirty As IDocumentDirty2
    Set pDocDirty = Application.Document
    pDocDirty.SetClean
End Function