DocumentBase.BeforeClose Event

Occurs immediately before the document closes.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

public event CancelEventHandler BeforeClose

The event occurs before the document closes. To keep the document from closing, set the Cancel argument of the provided CancelEventArgs object to true.

The following code example displays a message box before the document closes. To use this example, run it from the ThisDocument class in a document-level project.

private void DocumentBeforeClose()
{
    this.BeforeClose += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforeClose);
}

void ThisDocument_BeforeClose(object sender, System.ComponentModel.CancelEventArgs e)
{
    MessageBox.Show("The document is closing.");
}

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft