How to call a VSTO AddIn method from a separate C# project?

前端 未结 4 2080
情深已故
情深已故 2020-12-10 07:14

I have a C# Excel Add-in project \"MyExcelAddIn\" that has a public method Foo() to do something complex. For testing purposes, the add-in also defines a toolbar button whic

4条回答
  •  独厮守ぢ
    2020-12-10 07:32

    For anyone else who finds this here's what I did:

            object addInName = "AddinName";
            var excelApplication = (Microsoft.Office.Interop.Excel.Application)Marshal.GetActiveObject("Excel.Application");
            COMAddIn addIn = excelApplication.COMAddIns.Item(ref addInName);
    
            addIn.Object.AddinMethodName(params);
    

    Also had to add a reference to Microsoft.Office.Core under COM and Excel.Interop under Assemblies.

提交回复
热议问题