Programmatically close out of an ArcMap document without being prompted to save document file

Last Published: April 25, 2020


Instructions provide sample code which allows the current ArcMap document to close without prompting the user whether to save edits to the document file.


This code can be added to a map document or a template. Adding it to a template means it will be used by all MXD files based on the template.

  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand the Project folder, select ThisDocument, right-click, and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all your map documents open the Normal.mxt ThisDocument code module instead.

  4. Paste the following code into the code module.

    Private Function MxDocument_BeforeCloseDocument() As Boolean
    Dim pdoc As IMxDocument
    Set pdoc = ThisDocument
    Dim pdirty As IDocumentDirty2
    Set pdirty = pdoc
    End Function

  5. Close the Visual Basic Editor.
  6. Save the map as an MXD document or MXT template.

    When using either an MXD or MXT containing this code, ArcMap will not prompt whether changes should be saved when the application closes.

Article ID:000006317

  • ArcMap 8 x
  • ArcMap 9 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options