Document.BeforeClose Event

 

Occurs immediately before the document closes.

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

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. This example is for an application-level add-in.

private void DocumentBeforeClose()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.BeforeClose += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforeClose);
}

void ThisDocument_BeforeClose(object sender, System.ComponentModel.CancelEventArgs e)
{
    System.Windows.Forms.MessageBox.Show("The document is closing.");
}
Return to top
Show: