Document.BeforeClose 事件 (2007 系統)

更新: 2008 年 7 月

在關閉文件之前立即發生。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v9.0 (在 Microsoft.Office.Tools.Word.v9.0.dll 中)

語法

Public Event BeforeClose As CancelEventHandler

Dim instance As Document
Dim handler As CancelEventHandler

AddHandler instance.BeforeClose, handler
public event CancelEventHandler BeforeClose

備註

此事件會在關閉文件之前發生。若要防止文件關閉,請將提供的 CancelEventArgs 物件的 Cancel 引數設定為 true。

範例

下列程式碼範例會在關閉文件之前顯示訊息方塊。

Private Sub DocumentBeforeClose()
    AddHandler Me.BeforeClose, AddressOf ThisDocument_BeforeClose
End Sub

Private Sub ThisDocument_BeforeClose(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    MessageBox.Show("The document is closing.")
End Sub
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.");
}

這是示範應用程式層級增益集的版本。

Private Sub DocumentBeforeClose()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    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
private void DocumentBeforeClose()
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    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.");
}

使用權限

請參閱

參考

Document 類別

Document 成員

Microsoft.Office.Tools.Word 命名空間

變更記錄

日期

記錄

原因

2008 年 7 月

加入應用程式層級增益集的程式碼範例版本。

SP1 功能變更。