I am getting this error when closing an "add-in" workbook (.xla) using the Workbook.Close() method:
error 1004:
"This workbook is currently referenced by another workbook and cannot be closed."
I closed every other workbook visible from the VBA Editor. Now the "add-in" workbook is the only open workbook, but I still get the error with ThisWorkbook.Close(). Resetting the project in the VBA editor with the "Stop button" did not help.
Why is Excel thinking that this workbook is currently referenced by another workbook ? (edit: there is no other workbook, I closed them all. At this point there is only one workbook open, and only one VBA project appearing in the VBA editor)
It seems somehow a reference has been leaked. Is there a way to avoid this bug ?
ThisWorkbook
is not the workbook you think it is? – HamboneThisWorkbook.Close
. ThisWorbook cannot possibly refer to another workbook because all other workbooks have been closed. – ThreeStarProgrammer57