Xll does not work if Excel is created programatically

Add-in Express™ Support Service
That's what is more important than anything else

Xll does not work if Excel is created programatically
 
Subscribe
Steve Weixel




Posts: 7
Joined: 2024-01-05
I had this issue previously with a different kind of add-in, when running Excel by calling CreateObject. The solution was to deselect and reselect the addin and that would make it work. However that isn't working for my xll module add-in. It's not in the addins collection, and when I look at it through Excel's add-in options it shows the file name instead of the addin name.
Posted 21 May, 2024 22:39:37 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11
Hello Steve,

If started programmatically, Excel doesn’t load Excel add-ins (Excel UDFs). This is by design. There was an old article where they explained the reasons behind this design decision and how you could load an XLL load in this case. That article is now removed; its URL was https://support.microsoft.com/en-us/help/213489/add-ins-do-not-load-when-using-the-createobject-command-in-excel.

That page suggested to bypass this restriction by calling ExcelApp.RegisterXll; see https://learn.microsoft.com/en-us/office/vba/api/excel.application.registerxll. I remember doing this in the very first WindowActivate event that my COM add-in received; I don't remember the Excel version I used.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2024 08:43:15 Top
Steve Weixel




Posts: 7
Joined: 2024-01-05
Thanks, I'll try that.

Question. The example is:
Application.RegisterXLL "XLMAPI.XLL"


Do I put my own DLL as the file name, e.g. MyFunction.dll, or do I put the loader dll, e.g. adxloader64.MyFunction.dll?
Posted 22 May, 2024 13:11:24 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11
I believe, the loader DLL.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2024 13:41:34 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11

string assemblyPath = Assembly.GetExecutingAssembly().CodeBase;
bool result = ExcelApp.RegisterXLL(Path.Combine(Path.GetDirectoryName(assemblyPath), "adxloader.MyAddin1.dll"));


Note that it was written in the 32bit times. And I'm not sure if it works at all.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2024 13:49:51 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11
Andrei Smolin writes:
I remember doing this in the very first WindowActivate event


I was wrong. The code lines above are located in the event handler of the WorkbookActivate event.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2024 14:02:08 Top
Steve Weixel




Posts: 7
Joined: 2024-01-05
I just want to follow up that calling RegisterXLL on the loader dll worked, thanks.
Posted 24 Jul, 2024 13:58:03 Top
Andrei Smolin


Add-in Express team


Posts: 19011
Joined: 2006-05-11
Thank you, Steve!

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jul, 2024 16:05:46 Top