Workbook.BeforePrint 事件 (2007 system)

更新: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 命名空间