How to Best Reuse Functions in Multiple Add-Ins

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

How to Best Reuse Functions in Multiple Add-Ins
 
Mac McClanathan




Posts: 10
Joined: 2017-02-09
Hello,

What is the best way to store functions that I can reuse in multiple add-ins? For example, I would like to create a function that gets passed a name of an Excel table and it verifies that the table exists. And, I would like to re-use that function in multiple add-ins. What is the best way of accomplishing that?

I tried just adding a class to a current Excel COM Add-In and putting the function there, but as soon as I tried to reference the Excel Object it didn't recognize it.

Thanks!
Jeremy
Posted 09 Feb, 2017 02:12:24 Top
Marcus Datascout




Posts: 25
Joined: 2015-04-12
Hiya Jeremy,

For this you'll want to create a DLL (Dynamic Linked Library). This is a stand-alone project to house commonly used functionality.

For example, I add error logging to each of my add-ins. Rather than import to the log class into every add-in project, I create a separate DLL for logging and then simply reference it from each add-in.

This should get you started
http://www.c-sharpcorner.com/article/creating-C-Sharp-class-library-dll-using-visual-studio-net/

Cheers - Marcus
Posted 09 Feb, 2017 03:35:14 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Thank you, Marcus!!!

Hello Jeremy,

I think you would need NOT to use your email address as a login.

jeremy.mcclanathan@gmail.com writes:
I tried just adding a class to a current Excel COM Add-In and putting the function there, but as soon as I tried to reference the Excel Object it didn't recognize it.


You can pass an Excel.Application object to that class' constructor. The class could store the reference for using it.

Alternatively, you can access the Excel.Application your add-in is provided at startup:

{add-in project name such as MyAddin1}.AddinModule.CurrentInstance.ExcelApp

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 09 Feb, 2017 08:54:17 Top
Mac McClanathan




Posts: 10
Joined: 2017-02-09
Hello,
I followed the directions in the link, got the class library to work and got a successful build. But, when I ran the addin in Excel it through an exception and said it couldn't find class library. Is there something I need to do to package class library dll with the addin?
Thanks!
Jeremy
Posted 10 Feb, 2017 02:50:28 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Hello Jeremy,

Make sure your setup project deploys it. You may prefer to let Add-in Express generate a new setup project.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Feb, 2017 03:14:38 Top
Jeremy McClanathan




Posts: 10
Joined: 2017-02-09
Thank you. How do I make sure my project deploys it? I tried un-registering the project and re-registering it.
Jeremy
Posted 10 Feb, 2017 15:05:21 Top
Jeremy McClanathan




Posts: 10
Joined: 2017-02-09
I figured it out. The class library I created didn't have a strong name by defaut and needed one.
Thanks
Jeremy
Posted 12 Feb, 2017 13:41:18 Top