title: Cannot close workbook because Excel 2010 thinks it is still being referenced
body: <p>I have an Excel 2010 macro application that is made up of several workbook files.</p>
  
  <p><strong>FileName (ProjectName)</strong> <br>
  VFApp.xlsm (VFAppVBA)<br>
  VFReportClasses.xlsm (VFReportVBA)<br>
  VFImportClasses.xlsm (VFImportVBA)<br>
  VFDataClasses.xlsm (VFDataVBA)<br>
  ZShared.xlsm (ZSharedVBA)</p>
  
  <ul>
  <li>Shared is referenced by all the other workbooks.</li>
  <li>Data is referenced by App, Report, &amp; Import.</li>
  <li>Report and Import are both referenced by App.</li>
  </ul>
  
  <p>I'm trying to close all the referenced files when the App file is closed. This works for everything except ZShared.xlsm.  For it I get the <strong>'This workbook is currently referenced by another workbook and cannot be closed.'</strong> error.</p>
  
  <p>The only semi-helpful info I found online was <a href="http://support.microsoft.com/kb/211856" rel="nofollow">http://support.microsoft.com/kb/211856</a>
  and <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;159794" rel="nofollow">http://support.microsoft.com/default.aspx?scid=kb;en-us;159794</a>.  I added some logging to all the classes in ZShared. All instances of it's classes are getting correctly terminated and I don't have any workbook objects pointing to ZShared. </p>
  
  <p>I even tried renaming the files like (http://www.allquests.com/question/3996335/Upgrading-Add-ins-from-XL2003-to-XL2007.html).</p>
  
  <p>The weird thing is, if I manually open VFDataClasses.xlsm before opening VFApp.xlsm, then ZShared will close out correctly without error.  If I just open VFApp.xlsm and let it open all the other referenced files, I get the above error.</p>
  
  <p>Anybody have any suggestions for figuring out why Excel thinks the workbook is still referenced? </p>
  
  <p><strong>Clairification:</strong> </p>
  
  <ul>
  <li>Each workbook references the others via Tools -> References. </li>
  <li>ZShared consists of public classes and modules with public subs, functions, and constants as well as 3 global variables. </li>
  <li>I'm not, that I know of, doing anything to reference ZShared's workbooks or other Excel objects. </li>
  <li>The global variables are in ZShared so I don't have to recreate them in each App that references ZShared. They are handled via public <code>InitializeGlobalClasses</code> and <code>TerminateGlobalClasses</code> </li>
  <li>I added an <code>m_InstanceId</code> to every class and debug logging to all <code>Class_Initialize</code> and <code>Class_Terminate</code> so I am 100% certain that all instances of the classes are being terminated correctly. </li>
  </ul>
  
  <p>I wonder if it is possible Excel is creating some hidden reference to the workbook based on using a <code>With</code> statement or some such that isn't being cleared correctly. On the other hand, it makes no sense that this would only happen if ZShared was not already open when the App started.</p>