Microsoft KB Archive/306446

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

Article ID: 306446

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft Excel 2002 Standard Edition

-



This article was previously published under Q306446



For a Microsoft Excel 2000 version of this article, see 284864.



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

Microsoft Excel has encountered a problem and needs to close. We are sorry for the inconvenience.

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



RESOLUTION
To resolve this problem, obtain the latest service pack for Microsoft Office XP. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

307841 OFFXP: How to Obtain the Latest Office XP Service Pack



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft Office XP Service Pack 1.



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

