Pieter van der Westhuizen

Office 2013 add-ins & Visual Studio 2012: Getting started for VSTO developers

So you’ve been using Visual Studio Tools for Office (VSTO) for some time now and luckily you’ve discovered a better and easier way to develop Office add-ins, namely Add-in Express. You’ve already spoken to our friendly sales staff and bought your own license of Add-in Express.

Ready to start a new happier life of creating awesome Office extensions (including plug-ins for Outlook, Excel, Word, PowerPoint etc.) you excitedly fire up Visual Studio and hit File, New Project. You will notice Add-in Express provides four Visual Studio project templates which you will find under Other Project Types > Extensibility:

Visual Studio project templates provided by Add-in Express

Add-in Express project types

ADX COM Add-in

This project template is used to create add-in for any of the Microsoft Office applications and will probably be the starting point for most of your Office extensions. This project type can also contain RTD servers, smart tags and XLL add-ins.

ADX RTD Server

If you need to create a standalone Real-time data server for Excel, this is the project template you can use. This project template will add all the required code and give you the tools to quickly and easily create an RTD server.

ADX Smart Tag

This project template will allow you to create a SmartTag library for Word, Excel, PowerPoint and Outlook. It includes visual designers that make it easy to create a new smart tag.

ADX XLL Add-in

To create user-defined functions and custom function categories for Excel, used to be a real challenge. This project template gives visual designers a sample to get you started with creating your own XLL Add-in.

The new project wizard

All new Add-in Express projects start with the new project wizard. This wizard automates what otherwise would’ve taken hours to code manually using VSTO.

Multiple versions supported: Office 2013 – 2000

The first page of the wizard prompts you to choose the programming language you would like to use to develop your add-in. This can be C#, VB.NET or Visual C++.

Selecting a programming language and the minimum supported Office version

Secondly, you get to choose which version of Office your add-in needs to support by choosing the minimum supported Office version. For example, if you choose Microsoft Office 2003 as the minimum supported version your add-in will work in all newer versions of Office from 2003 to Office 2013. It will most likely also work in the next yet unreleased version of Office.

The real awesomeness of this feature can get lost if you do not compare it with how to accomplish version independence using VSTO. Truth is, you can’t really do this with VSTO without having to create separate projects for the different versions of Office or by jumping through a crazy amount of unsupported hoops.

One add-in, multiple Office applications

The next page of the new project wizard also makes something that would otherwise be impossible to accomplish with VSTO as easy as checking a few checkboxes – supporting several Office applications with one project.

Supporting several Office applications with a single project

With VSTO if you want an add-in to share functionality between different Microsoft Office applications, you would need to create separate projects for each application. For example, if you want to create an add-in using VSTO to support Microsoft Excel, Word and Outlook for Office 2007, 2010 and 2013 you would end up with six different projects – a nightmare to maintain!

Add-in Express takes care of this for you. You can support ALL of the Office applications and versions with a single project and codebase. Life could not be better!

Signing the assembly

The final step in the wizard allows you to either select an existing strong name file or to simply let it create one for you.

Signing the assembly with strong names

The wizard will also automatically sign your assembly using either the strong name file you’ve selected or the new one it created.

The wizard automatically signs your assembly using either the existing or a new strong name

The wizard takes care of the infrastructure of creating your add-in, leaving you to focus on your application’s functionality.

Solution architecture

VSTO and Add-in Express differ greatly in the way they structure your Office extension project layout and how their architectures work.

VSTO project architecture

Any VSTO project is centred on the ThisAddIn.cs class and the project layout is pretty straight forward.

VSTO project architecture

The StartUp and Shutdown event handlers are already declared for you in the InternalStarup method:

private void InternalStartup()
    this.Startup += new System.EventHandler(ThisAddIn_Startup);
    this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);

You’ll add most of the logic of your add-in inside this class. If you need to add ribbons or Outlook Form Regions, you need to add new separate items to your VSTO project.

Add-in Express architecture

An Add-in Express project is centred on the AddinModule.cs class and it already contains all the required references to the correct Interop libraries for the version of Office you selected.

Add-in Express project architecture

Inside the AddinModule.cs class you’ll find properties to all the Office applications you’ve chosen to support. Each property is a reference to the host application your add-in is running in. In the following code listing, you’ll see references to the Excel, Word and Outlook Application objects:

public Excel._Application ExcelApp
		return (HostApplication as Excel._Application);
public Word._Application WordApp
		return (HostApplication as Word._Application);
public Outlook._Application OutlookApp
		return (HostApplication as Outlook._Application);

When you double-click on the AddinModule.cs file inside the Visual Studio Solution Explorer, it will open a visual design surface. Add-in Express make it easy to discover various features of Office by allowing you to add and design numerous UI elements visually by simply clicking on their respective icons on the visual designer toolbar.

Add-in Express visual designer toolbar

This is a truly RAD approach which will allow you to quickly design the Office UI elements your add-in requires and help you to focus on your add-in’s functionality rather than having to focus on getting “plumbing” code to work.

Thank you for reading. Until next time, keep coding!

Office 2013 add-ins and VS 2012: Getting started for VSTO developers

You may also be interested in:

Post a comment

Have any questions? Ask us right now!