Udostępnij za pośrednictwem


Zdarzenie Document.BeforeClose

Pojawia się natychmiast, przed zamknięciem dokumentu.

Przestrzeń nazw:  Microsoft.Office.Tools.Word
Zestawy:   Microsoft.Office.Tools.Word.v4.0.Utilities (w Microsoft.Office.Tools.Word.v4.0.Utilities.dll)
  Microsoft.Office.Tools.Word (w Microsoft.Office.Tools.Word.dll)

Składnia

'Deklaracja
Event BeforeClose As CancelEventHandler
event CancelEventHandler BeforeClose

Uwagi

Zdarzenie występuje przed zamknięciem dokumentu.Aby zachować dokument od zamknięcia, należy ustawić Cancel pod warunkiem argumentu CancelEventArgs sprzeciw w stosunku do true.

Przykłady

Poniższy kod wyświetla okno komunikatu, przed zamknięciem dokumentu.W tym przykładzie jest na poziomie aplikacji dodatek.

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
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.");
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

Document Interfejs

Przestrzeń nazw Microsoft.Office.Tools.Word