Microsoft.Office.Tools.Excel.ApplicationFactory.GetVstoObject导致VBA内存泄漏?

下面是VSTO-Project的一个最小示例,它强制Excel VBA环境显示错误“内存不足”,并导致VBA-Project出现两次。

问题:这是“GetVstoObject”-Method中的一个错误。 我怎样才能解决?

脚步:

  1. 在Excel 2010中:创build一个新的工作簿并按ALT + F11进入VBA环境
  2. 在VBA.ThisWorkworkbook:创build一个空的新的子

    小测()

    结束小组

  3. 将工作簿保存为Test.xlsm并退出Excel。

  4. 在Visual Studio中创build一个新的Excel 2010加载项
  5. 用下面的代码replaceThisAddIn.cs中的所有代码。
  6. 用F5开始debuggingExcel
  7. 用F5开始debuggingExcelAddIn1
  8. 打开保存的工作簿Test.xlsm
  9. 重新打开保存的工作簿(重要:必须“外部”,例如通过使用Windows任务栏中的Excel跳转列表)

结果:

  • CTP翻了一番
  • 如果按ALT + F11打开VBA,将会得到“没有足够的内存” – 错误

感谢您的任何解释/解决scheme!

问候,Jörg


C#最小插件代码:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Excel = Microsoft.Office.Interop.Excel; using Office = Microsoft.Office.Core; using Microsoft.Office.Tools.Excel; namespace ExcelAddIn1 { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.WorkbookActivate += new Excel.AppEvents_WorkbookActivateEventHandler(Application_WorkbookActivate); } void Application_WorkbookActivate(Excel.Workbook Wb) { //This is the important line: var activeVstoWorkbook = Globals.Factory.GetVstoObject(Wb); } #region VSTO generated code private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); } #endregion } }