Share via


WorkbookBase.BeforePrint 이벤트

이 이벤트는 통합 문서(또는 통합 문서의 내용)를 인쇄하기 전에 발생합니다.

네임스페이스:  Microsoft.Office.Tools.Excel
어셈블리:  Microsoft.Office.Tools.Excel.v4.0.Utilities(Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

구문

‘선언
Public Event BeforePrint As WorkbookEvents_BeforePrintEventHandler
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.");
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

WorkbookBase 클래스

Microsoft.Office.Tools.Excel 네임스페이스