XL: Cannot Use Workbook_BeforeClose Event to Close a Workbook (816138)
The information in this article applies to:
- Microsoft Excel 2002
- Microsoft Excel 2000
- Microsoft Excel 97 for Windows
SYMPTOMSWhen 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. CAUSEThis 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.WORKAROUNDTo 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.
Modification Type: | Major | Last Reviewed: | 5/28/2003 |
---|
Keywords: | kbnofix kbBug KB816138 |
---|
|