I have a C # Excel add-in project MyExcelAddIn that has the public Foo () method to do something complicated. For testing purposes, the add-in also defines a toolbar button that is connected to Foo (), so I can check this and make sure that clicking the button calls Foo () and does what I want to do. This is normal.
Now I want to call this method from a C # Windows Forms project. In a Windows Forms project, I can create an Excel instance and make it visible and check if my VSTO add-in works, since I can see the button and it works. But I canโt decide how to call Foo () programmatically from a Windows Forms project. I searched a little Google and reached the COMAddIn object "MyExcelAddIn", but I canโt decide how to call Foo ().
It looks something like this:
// Create Excel and make it visible Application excelApp = new Application(); excelApp.Visible = true; // I know my VSTO add-in is running because I can see my test button // Now get a reference to my VSTO add-in Microsoft.Office.Core.COMAddIns comAddIns = _excelApp.COMAddIns; object addinName = "MyExcelAddIn"; Microsoft.Office.Core.COMAddIn myAddin = comAddIns.Item(ref addinName); // This works, but now what? How do I make a call on myAddin? // Note that myAddin.Object is null...
So, I want to know what I can do to call Foo () from my Windows Forms application. Note that I have full control over the Windows Forms application and add-in, and I suspect that I have to make changes to both of them (especially the add-in), but I have no idea how to do this.
Please note that this is VS2008 C # application and I am using Excel 2003.
source share