1
votes

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 ?

1
Have you referenced any other workbook(s) within the code? Is it possible ThisWorkbook is not the workbook you think it is?Hambone
To Hambone's point can you provide the code you are using in this context and the line that it errors out on.nbayly
@Hambone No, because the error happens even when all other workbooks have been closed. At this point there is only one workbook open, and only one VBA project appearing in the VBA editor. And this lone workbook cannot be closed because "it is referenced by another workbook". This is weird.ThreeStarProgrammer57
@nbayly The code is a one liner: ThisWorkbook.Close. ThisWorbook cannot possibly refer to another workbook because all other workbooks have been closed.ThreeStarProgrammer57

1 Answers

1
votes

I was able to replicate the error but only when the file (AddIn \ Workbook) is self referenced (see fig below).

AddIn - Self Referenced VbProject

Suggest to terminate Excel, then rename the Addin file and open it. Now it the `AddIn shall be closed whitout problem (see fig below).

Renamed AddIn - Self Referenced VbProject