Search code examples
excelvstoadd-inexcel-dnaxll

How to use the RegisterXLL method in a C# VSTO for Excel


I have created a xll addin using ExcelDNA so that it can be easily written in C#.

I also have a VSTO and I want the VSTO to Register the xll file, so that I can use the custom functions when the user is using the VSTO plugin for excel.

This is what is written in the Addin startup method:

Application.RegisterXLL(@"SMPXLL.xll");

It would work if I wrote the absolute address of the .xll file. However, I want it to be a relative address. I just don't know what the file is relative to.


Solution

  • Application.RegisterXLL(...) works fine for Excel-DNA add-ins.

    You can find the path of the executing assembly (the VSTO library) using code like this: How do I get the path of the assembly the code is in?

    Then build the full path to the .xll file relative to that path.