Excel VBA project not getting closed

徘徊边缘 提交于 2019-12-05 22:51:16

The problem was with workbook objects remaining in the memory. By clearing the objects in the workbook deactivate event, the VBA project is getting closed when I close the workbook.

See this: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/377fbebc-021d-4e48-aaef-d4658cc221b3

Thanks

I had a similar problem in my COM-Add-In (C# / VSTO):

  • You have to release all Workbook references in your code when the workbook is closed and set them to null.
  • If you internally store a reference to a workbook, always use WeakReference to let the Garbage Collector do its work.

In my case I had a Windows.Forms.Tree of all workbooks in a custom task pane. The referenced Workbook objects were stored in the TreeNode.Tag. After I had closed a workbook, the tree was updated by events, but at this time I had already generated what I've called a VBA Workbook "ghost". I solved this by replacing the Workbook-Objects in the TreeNode tags by the Workbook.FullName-String (to reference them later).

Hope it helps, Jörg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!