References to Closed Workbook

You may have used the References dialog on the Tools menu to create a reference from one workbook to another. In Microsoft Excel 97, before closing a workbook that has a reference to an object (even if the reference is to a closed workbook) you must first set the object to Null.

Consider the following example in which First.XLA is referenced by Second.XLA, and the code is contained in Third.XLA:

Set wbCode = Workbooks.Open "First.XLA"
wbCode.Close
Workbooks.("Second.XLA").Close

This code will fail and produce an error message stating that Second.XLA is "Currently referenced by another project and cannot be closed." The workaround is as follows:

Set wbCode = Workbooks.Open "First.XLA"
wbCode.Close
set wbCode = Null
Workbooks.("Second.XLA").Close    'Will now close as wbCode = Null