1
votes

I am using excel-dna as base function, then I call a "vsto" function from an addin to trigger a web service request on the selected function. My issue is that I d like to use the DNA function to parse the ranges to be send to the service. It return a string currently ("waiting for service call..."), and if the VSTO methods call the function it passed another variable to return something else.

I cannot extract other thing than string, object comes back empty when I use "evaluate" in vsto.

I think the best way would be to reach a global cache variable stored in the vsto addin from the excel-dna function. I could not manage to to this.

Addins button push => addins evaluate Excel DNA => DNA store data in VSTO Addin variable => VSTO call the service and paste the returning data.

Thank you,

2

2 Answers

1
votes

Ok I found out on: MSN Blog

namespace AddIn{

    [ComVisible(true)]
    [Guid("****************************")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IAddinUtilities
    { void youraddinfunction();
    }

  [ClassInterface(ClassInterfaceType.None)]
    public partial class ThisAddIn : IAddinUtilities
    {
        protected override object RequestComAddInAutomationService()
        { return this; }

        public void yourfunction (){ DoSomething }   
}

In the excel Dna function :

var application = (Application)XL.ExcelDnaUtil.Application;

            var addin = application.COMAddIns.Item(AddinName);
            var what = addin.Object;
            what.youraddinfunction;
0
votes

Yoyo's approach is strictly speaking correct, but for an approach that is more portable, I suggest combining ExcelDNA with NetOffice. Here is a snippet to get you started. Note that you will need to cleanup your Application references to COM proxy objects in the OnDisconnection method. For more details, check out Excel Addin Portability Tutorial

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ProgId("Sample.MyAddIn")]
public class MyRibbon : ExcelRibbon
{

   public override void OnConnection(object comApp, ext_ConnectMode ConnectMode, object objAddin, ref Array custom)
   {
     // glue NetOffice + Excel DNA
     m_ExcelApplication = new Application(null, m_ComApplication);
     // other initialization... 
   }
}