Globals.ThisAddIn is null when I call it from UDF

308 views
Skip to first unread message

Alexander Kovalenko

unread,
May 12, 2015, 12:20:00 PM5/12/15
to exce...@googlegroups.com
Hi all,

Scenario:
1. I've created a VSTO Add-In project.
2. Created a class public class RtdManager : ExcelRtdServer
3. Created a method like:
    [ExcelFunction]
    public static object GetRtdTime(){
         Excel.Worksheet ws = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveSheet);
         ...
    }

Issue: Globals.ThisAddIn is null when I try to call from UDFs.

I've read https://exceldna.codeplex.com/documentation but didn't find solution.
Could you help me find some more docs about ExcelDna, Rx, ExcelRtdServer, etc, please.

Thanks,
Alexander

Govert van Drimmelen

unread,
May 12, 2015, 2:21:55 PM5/12/15
to exce...@googlegroups.com, akov...@gmail.com
Hi Alexander,

Mixing Excel-DNA and VSTO in one add-in won't work. Globals.ThisAddIn is related to VSTO.
The best starting point for an Excel-DNA add-in is to make a plain "Class Library" project and the install the "Excel-DNA" package from NuGet.

If you need to get to the Excel COM object model from an Excel-DNA add-in, you can call ExcelDnaUtil.Application. This returns an object that is a Microsoft.Office.Interop.Excel.Application. You can reference the Excel interop assembly Microsoft.Office.Interop.Excel, and use it from there.

The context where UDFs run is more restricted than normal macros, so I normally recommend avoiding the COM object model inside UDF functions where possible. I'm, not sure what you were intending to do with the ActiveSheet...

Sadly there's not much more documentation for Excel-DNA beyond the limited documentation on the CodePlex site, and the posts in the Google group. But I'm happy to answer any specific questions you might have.

-Govert

Alexander Kovalenko

unread,
May 14, 2015, 9:46:07 AM5/14/15
to exce...@googlegroups.com
Hi Govert,

Thank you very much for detailed explanation.

Thanks,
Alexander
Reply all
Reply to author
Forward
0 new messages