共用方式為


Workbook.BeforePrint 事件 (2007 系統)

更新:2007 年 11 月

在列印活頁簿 (或其中任何資料) 前發生。

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

語法

Public Event BeforePrint As WorkbookEvents_BeforePrintEventHandler

Dim instance As Workbook
Dim handler As WorkbookEvents_BeforePrintEventHandler

AddHandler instance.BeforePrint, handler
public event WorkbookEvents_BeforePrintEventHandler BeforePrint

範例

下列程式碼範例會示範 BeforePrint 事件的處理常式。這個事件處理常式會提示使用者繼續或取消列印作業。如果使用者取消列印作業,則 WorkbookEvents_BeforePrintEventHandler 事件處理常式的 Cancel 參數會設為 true,因此 Microsoft Office Excel 便不會列印這個活頁簿。

這是示範文件層級自訂的範例。

Sub ThisWorkbook_BeforePrint(ByRef Cancel As Boolean) _
    Handles Me.BeforePrint

    If DialogResult.No = MessageBox.Show("Are you sure " & _
        "you want to print the workbook?", _
        "Sample", MessageBoxButtons.YesNo) Then
        Cancel = True
        MessageBox.Show("Print is canceled.")
    End If
End Sub
private void WorkbookBeforePrint()
{
    this.BeforePrint +=
        new Excel.WorkbookEvents_BeforePrintEventHandler(
        ThisWorkbook_BeforePrint);
}

void ThisWorkbook_BeforePrint(ref bool Cancel)
{
    if (DialogResult.No == MessageBox.Show("Are you sure " +
        "you want to print the workbook?",
        "Example", MessageBoxButtons.YesNo))
    {
        Cancel = true;
        MessageBox.Show("Print is canceled.");
    }
}

使用權限

請參閱

參考

Workbook 類別

Workbook 成員

Microsoft.Office.Tools.Excel 命名空間