Creating an Office COM add-in: getting started for VB developers

In today’s article I’ll take a break from my usual C# and return to my roots as a VB developer. We’ll take a whirlwind trip through some of the features of Add-in Express and how to use it using Visual Studio 2010 and Visual Basic.Net

Getting Started

Let’s start by creating a new ADX COM add-in, which is available under Installed Templates> Other Project Types> Extensibility.

Click OK and you’ll be presented with the New Microsoft Office COM Add-in wizard. On the first screen you can select your programming language, which in our case will be Visual Basic. You should also choose which version of Office will be the minimum version your add-in supports. Bear in mind that certain features are only available in newer versions of Office, so choose carefully (for more info, please see Supporting several Office versions in an add-in. Interop assemblies and late binding.). In our scenario we’ll choose Microsoft Office 2007.

Click Next. You can choose to generate a new strong name file or use an existing one. Choose Generate new for now. If you need to use another string name file later on, you can select it in your projects’ properties Signing tab.

Click Finish to complete the wizard, the Add-in Module Designer should then open automatically, if not, open it by double-clicking on AddinModule.vb in the Solution Explorer.

Need Help and the latest version?

Add-in Express added a Help panel at the bottom of the AddinModule designer surface to help you quickly access the wealth of help and resources on their website. You can also use it to quickly check which version of Add-in Express you’re using.

Adding UI elements

Add a ribbon tab by clicking on the ADXRibbonTab button on the designer toolbar. Select the ribbon tab component and expand the designer by clicking on the two up arrows. Using the designer toolbar, add three ribbon groups (ADXRibbonGroup) and also add a button to each group.

Set the Ribbon Tab’s Ribbons property to OutlookMailRead;OutlookContact;ExcelWorkbook;WordDocument and choose where the ribbon groups should appear by setting the Ribbons property for each:

OutlookRibbonGroup.Ribbons = OutlookMailRead;OutlookContact

ExcelRibbonGroup.Ribbons = ExcelWorkbook

WordRibbonGroup = WordDocument

By setting the Ribbons’ property you can choose where your UI elements should show. In the above example the Outlook group will only show in Outlook when an e-mail is read and when the user opens a Contact item.

Using the Office objects

Now that we have all the necessary UI elements, let’s have a look at the code behind the scenes. Switch to the Add-in Module’s code by clicking on the View Code button on the Solution Explorer toolbar. You’ll see the three important properties we need in order to gain access to the MS Office objects:

Each of these properties exposes the running MS Office application and allows you to gain access to it. Add an event handler for the OutlookRibbonButton‘s OnClick event by selecting it in the code-behind object dropdown, and selecting the OnClick event in the event dropdown.

This will automatically generate the event handler code for you. Add the following code to it:

The code will check the type of the current Inspector item, and show a messagebox specific to the item type. Next, add an event handler for the Excel button in a similar fashion as above and add the following code:

This code will loop through a list of running processes on your system and populate the active worksheet in the Excel workbook. Finally add an event handler for the Word ribbon button, add the following code to it:

The above code will perform a similar task as the Excel button, but this time it will add the list of running processes to a MS Word table.

Testing your add-in

Once you’re satisfied with your UI and code logic, build your project by selecting Build Solution from the Visual Studio Build menu. After the project has been built successfully, select Register ADX Project from the same Build menu, this will register your Add-in for use by MS Office. After the project has been registered, run your project by pressing F5. If you want to change the MS Office application you wish to test with, go to your projects’ property pages and on the Debug tab set the Start external program value to the desired MS Office application.

This technology is now available for our custom development services only. Based on the Add-in Express for Office core, it is designed for building custom-tailored Office add-ins with far less coding than you usually have to do. Plus, it includes all Add-in Express features such as True RAD, visual designers, Outlook view and form regions, etc.

Get the best platform for building version-neutral, fast and easy deployable plug-ins by using Add-in Express projects templates, visual designers, components and wizards in combination with a perfect Delphi compiler.

This is an extension for Visual Studio that allows developers to quickly create WiX-based setup projects in a familiar Visual Studio way.

The Designer for WiX Toolset lets you forget the plain Windows Installer XML and concentrate on your deployment logic. It integrates several editors with the Visual Studio IDE and provides a set of vdproj designers to configure the file system, registry, user interface, custom actions, launch conditions and more for your setup projects.

The innovative technology for customizing Outlook views and forms. It is included in all Add-in Express for Office products and can be used to extend Outlook views, e-mail, task and appointment windows, To-Do bar, Reading and Navigation panes with your own custom sub-panes.

Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in
the United States and/or other countries. All other trademarks are property of their respective owners.