English

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

Summary

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

Procedure

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
    Note:
    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.

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

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

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