Document.BeforeClose Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs immediately before the document closes.
public:
event System::ComponentModel::CancelEventHandler ^ BeforeClose;
event System.ComponentModel.CancelEventHandler BeforeClose;
member this.BeforeClose : System.ComponentModel.CancelEventHandler
Event BeforeClose As CancelEventHandler
Event Type
Examples
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.");
}
Private Sub DocumentBeforeClose()
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
AddHandler vstoDoc.BeforeClose, AddressOf ThisDocument_BeforeClose
End Sub
Private Sub ThisDocument_BeforeClose(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs)
System.Windows.Forms.MessageBox.Show("The document is closing.")
End Sub
Remarks
The event occurs before the document closes. To keep the document from closing, set the Cancel
argument of the provided CancelEventArgs object to true
.