Microsoft KB Archive/284864

= XL2000: Excel Stops Responding When Printing If You Cancel WorkbookBeforePrint Application Event =

Article ID: 284864

Article Last Modified on 6/27/2007

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q284864



SYMPTOMS
When you print or print preview your workbook, you receive the following error message:

Excel.exe has generated errors and will be closed by Windows. You will need to restart the program.

When you click OK, Excel quits.



CAUSE
This problem occurs when you create procedures for either of the following Microsoft Visual Basic for Applications events, and set the Cancel argument to True:
 * The WorkbookBeforePrint event of the Application object

-or-
 * The BeforePrint event of the Workbook object



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
You can use a Workbook object or Application object to run the BeforePrint or WorkbookBeforePrint event procedure whenever you print or print preview your workbook. However, when you attempt to change the Cancel argument to True for either of these events, you receive the error message described in the &quot;Symptoms&quot; section of this article.

Example of Problem
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Private Sub Workbook_BeforePrint(Cancel as Boolean) Static Ctr Ctr = Ctr + 1 If Ctr >2 then Cancel=True Else:Cancel=False MsgBox Ctr End Sub

