Microsoft KB Archive/816138

= You cannot use the Workbook_BeforeClose event to close another Excel workbook =

Article ID: 816138

Article Last Modified on 2/1/2007

-

APPLIES TO


 * Microsoft Office Excel 2007
 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Excel 97 Standard Edition

-



SYMPTOMS
When you programmatically open or close an Excel workbook, you may find that you cannot use the Workbook_BeforeClose event to close another Excel workbook.

For example, when you create and save a macro in Book2.xls that uses ThisWorkbook.Close to close Book2.xls and also uses the Workbook_BeforeClose event to close Book1.xls, the Book1.xls file is not closed as expected when you run the macro.



CAUSE
This occurs because the Saved property of the workbook is set as False after the workbook is saved. As a result, when you programmatically close a workbook, you cannot use the Workbook_BeforeClose event to close another workbook.



WORKAROUND
To work around this issue, close the workbook in the primary set of macros and do not use the Workbook_BeforeClose to close the workbook from another workbook.



MORE INFORMATION
For more information about the BeforeClose event, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/aa204871(office.11).aspx

Additional query words: XL2003 XL2007

Keywords: kbnofix kbbug KB816138

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.