none
Excel AddIn in separate project (winforms or wpf) RRS feed

  • Question

  • Hello folks,

    I've created Com Excel Addin in separate project. Then I've added this Excel Addin to my WPF solution. I've tried to invoke it like so:

    using Excel = Microsoft.Office.Interop.Excel; 

    var _excelApp = new Excel.Application();

    object name = "MyAddin";
    Office.COMAddIn addin = (Office.COMAddIn)_excelApp.COMAddIns.Item(ref name);

    addin.Connect = true;

    But all my efforts to invoke the Excel Addin from my WPF app were unsuccessful. I would greatly appreciate any help you can give me in working this problem.

    Tuesday, January 20, 2015 6:31 PM

Answers

  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/e2c4be57-5524-4fed-9de5-941f1ae444a3/excel-addin-in-wpf?forum=wpf
    • Marked as answer by hokushin Sunday, January 25, 2015 11:59 AM
    Sunday, January 25, 2015 11:59 AM

All replies

  • Hello,

    Did you try to iterate over all add-ins in the COMAddins collection and find yours instead of using the Item method? Have you registered the add-in before trying to find it?

    Did you develop an Excel or COM add-in? Note, the Excel object model provides the COMAddins and Addins properties.


    Tuesday, January 20, 2015 6:45 PM
  • Thanks a lot for prompt reply,

    I can install this add-in if I run it as a separate project. I need it for one Excel report only. So I need to invoke it dynamically before generating Excel report. Then I need to get rid of it.   

    Have you registered the add-in before trying to find it?

    I am pretty new to Office programming, so can you be more specific about the init process. Code snippet will be appreciated.

    Did you develop an Excel or COM add-in?

    It's COM add-in. I am using the lines below to remove it when sheet is closed:

     foreach (Office.COMAddIn addIn in adds)
                {
                    if (addIn.ProgId == "MyAddin" && addIn.Connect)
                    {
                        addIn.Connect = false;
                        break;
                    }
                }

    It works the way it's supposed to work.


    Tuesday, January 20, 2015 7:02 PM
  • Have you tried to use a similar code for enabling the add-in?

    foreach (Office.COMAddIn addIn in adds)
    {
       if (addIn.ProgId == "MyAddin" && !addIn.Connect)
       {
           addIn.Connect = true;
           break;
       }
    }

    Tuesday, January 20, 2015 7:17 PM
  • Thanks a lot for prompt reply. 

    I've got exactly the same error: HRESULT: 0x80004004 (E_ABORT))

    as in my case:

    var _excelApp = new Excel.Application();

    object name = "MyAddin";
    Office.COMAddIn addin = (Office.COMAddIn)_excelApp.COMAddIns.Item(ref name);

    addin.Connect = true;

    * Note that I am trying to invoke the add-in from separate wpf project. 

    Tuesday, January 20, 2015 7:38 PM
  • Hello folks!

    Any ideas what the problem is?

    So, I've created a small addin based on the sample below:

    https://code.msdn.microsoft.com/office/VSTO-Generate-tables-and-f19859b3

    Then I registered the COM addin project for COM Interop and added it to my WPF project. I can invoke this add-in if I run it as a separate project. In fact, I need this addin for one Excel report only. So I need to invoke it dynamically before generating the Excel report in question from my WPF UI app. Then I need to get rid of this addin.

    I am using the lines below to remove it when Excel sheet is closed:

     foreach (Office.COMAddIn addIn in adds)
                {
                    if (addIn.ProgId == "MyAddin" && addIn.Connect)
                    {
                        addIn.Connect = false;
                        break;
                    }
                }

    It works the way it's supposed to work.

    The problem is I can't invoke it dynamically using button click event in my WPF app. 

    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;

     private void Button_Click(object sender, RoutedEventArgs e)
     {

         var _excelApp = new Excel.Application();

          object name = "TablesAndCharts";
           Office.COMAddIn addin = (Office.COMAddIn)_excelApp.COMAddIns.Item(ref name);

           addin.Connect = true;

           _excelApp.Visible = true;

    }

    Wednesday, January 21, 2015 7:12 PM
  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/e2c4be57-5524-4fed-9de5-941f1ae444a3/excel-addin-in-wpf?forum=wpf
    • Marked as answer by hokushin Sunday, January 25, 2015 11:59 AM
    Sunday, January 25, 2015 11:59 AM