Over the years I have worked with a number of customers that still use/require the use of Shared Add-ins in Office. One customer I am working with today frequently has questions about implementations or encounters scenarios that are specific to Shared Add-ins.
If you have been working with Visual Studio for some time, you know there used to be a Shared Add-in template you could use to create an add-in. However, as of Visual Studio 2012, that template is now gone. Additionally, you might have found it was difficult to figure out how to implement Ribbons and TaskPanes.
With this in mind, I decided to publish on CodePlex a shared add-in template I have created for myself and that I think might be useful for others. The link is here:
How to Use It
Once you load this solution, you will find the Connect.cs. This is the MAIN entry point for the DLL solution. The first thing you will want to do is define which applications this add-in will pertain to. This is done via the ThisAddin_Register() method. There is an object called “office” where you will define each application you want to hook to:
office.AddApplication(OfficeBase.APPTYPE.EXCEL, “Excel Shared Addin Example”, “Excel Shared Addin Example”);
office.AddApplication(OfficeBase.APPTYPE.WORD, “Word Shared Addin Example”, “Word Shared Addin Example”);
office.AddApplication(OfficeBase.APPTYPE.POWERPOINT, “PowerPoint Shared Addin Example”, “PowerPoint Shared Addin Example”);
office.AddApplication(OfficeBase.APPTYPE.OUTLOOK, “Outlook Shared Addin Example”, “Outlook Shared Addin Example”);
The AddApplication command will allow you to specify which application will load. And if you look in the IDTExtensibility2 code region you will find the RegisterFunction method. This method will setup/install this DLL (when registered via RegAsm), to work with COM Automation and also register it in each application that you setup in the ThisAddin_Register() method:
foreach(OfficeBase.OfficeAddinInfo info in office.GetAddins()) {}
This template already comes with Ribbons for each of the applications, Word, Excel, PowerPoint and Outlook. It also automatically loads each from the Resources.
NOTE: Outlook requires a bit more work than what is provided.
If you look at my previous post on how to create a TaskPane in a Shared Com Add-in, you will see that this has been incorporated in this sample as well. To add a task pane, you will define your control and then call like this:
SharedCustomTaskPane myPane = CustomTaskPaneCollection.Add(dynamicControl, “My Pane”);
You will also want to change the attributes at the top of the class:
[GuidAttribute(“11111111-AF27-4814-9CBE-ED6A39A4B9A5”),
ProgId(“SharedAddin.Connect”),
ClassInterface(ClassInterfaceType.AutoDual)]
When the add-in loads in a parent application, it will determine the type and then setup the “office” object so that it contains the reference to the parent application. So to get Excel, you can make a simple call like this:
Excel.Application xlApp = office.GetExcel();
Likewise, there is a similar function for Word, PowerPoint, and Outlook. From there you can attach to events and make additional calls as needed.
Hopefully, you will find this solution useful. It has been very useful to me over the years, especially as I have added to it. There are still many uses for this type of Add-in and having all your code in one place – across all the Office applications can be very useful.
[…] https://davecra.com/2015/10/28/a-complete-shared-add-in-template/ […]
David thanks a lot for the post; I am using VS 2019 and your template is helpful . I have built and registered the DLL , but the task pane is not displayed.
Where do I use the following
Excel.Application xlApp = office.GetExcel(); // or any other Word Outlook etc
Not sure why the taskpane is not loaded. It might be that there is a problem with your Ribbon button that launches it or a problem with the registration of the taskpane itself. As for the GetExcel() options, this needs to be placed anywhere you need access to the instance of Excel (or other applications).