下面是一个最小样本VSTO-Project,它强制Excel VBA-Environment显示错误“内存不足”并导致VBA项目出现两次。
问题:这是“GetVstoObject”-Method中的错误。我该怎么办?
步骤:
在VBA.ThisWorkworkbook中:创建一个空的新Sub
子测试()
End Sub
将工作簿保存为 Test.xlsm 并退出Excel。
结果:
感谢您提供任何解释/解决方案!
此致 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
}
}