Build COM add-in for Word, PowerPoint, Excel
in C#, VB.NET: ribbon, menu, task pane

Add-in Express™
for Microsoft® Office and .net

Add-in Express Home > Add-in Express for Office and .NET > Online Guide > Building Office COM add-in

Building Office COM add-ins

The sample project below demonstrates how you create a COM add-in supporting several Office applications (Excel, Word and PowerPoint). The add-in creates a custom toolbar and adds a CommandBar button to the toolbar, main menu (in Office 2003 - 2000) and context menu, and a Ribbon button to the Ribbon UI of Microsoft Office 2007 - 2021/365. Also, the add-in creates an advanced task pane supporting versions 365/2021 - 2010 of the host applications. You can download the source code of the project as well as plenty more samples on the How-To pages: VB.NET examples for Office and C# examples for Excel.

A bit of theory

COM add-ins have been around since Office 2000 when Microsoft allowed Office applications to extend their features with COM DLLs supporting the IDTExtensibility2 interface (it is a COM interface, of course). COM add-ins is the only way to add new or re-use built-in UI elements such as command bar controls and Ribbon controls. Say, a COM add-in can show a command bar or Ribbon button to process selected Outlook emails, Excel cells, or paragraphs in a Word document and perform some actions on the selected objects. A COM add-in supporting Outlook, Excel, Word or PowerPoint can show advanced task panes in Office 365/2021 - 2000. In a COM add-in targeting Outlook, you can add custom option pages to the Tools | Options and Folder Properties dialogs. A COM add-in also handles events and calls properties and methods provided by the object model of the host application. For instance, a COM add-in can modify an email when it is being sent; it can cancel saving an Excel workbook or it can check if a Word document or selected text meets some conditions.

Per-user and per-machine COM add-ins

A COM add-in can be registered either for the current user (the user running the installer) or for all users on the machine. Add-in Express generates a per-user project; your add-in is per-machine if the addin module has ADXAddinModule.RegisterForAllUsers = True. Registering for all users means creating registry entries in HKLM and that means the user registering a per-machine plug-in must have administrative permissions. Accordingly, RegisterForAllUsers = False means writing to HKCU (=for the current user). See Registry keys.

Before you modify the RegisterForAllUsers property, you must unregister the add-in project on your development PC and make sure that adxloader.dll.manifest is writable.

A standard user may turn a per-user addin off and on in the COM Add-ins dialog. You use that dialog to check if your plugin is active.

Step 1. Creating a COM add-in project

Make sure that you have administrative permissions before running Visual Studio. Run Visual Studio via the Run as Administrator command.

In Visual Studio, open the New Project dialog and navigate to the Extensibility folder.

Creating a new COM Add-in project

Choose Add-in Express COM Add-in and click OK. This starts the COM Add-in project wizard. The wizard allows choosing your programming language (C#, VB.NET or C++) and specifying the oldest Office version your plugin needs to support. We are going to choose VB.NET and Office 2010.

Choosing your programming language

Choosing a particular Office version will add corresponding interop assemblies to the project. Later on you can replace interop assemblies and reference them in your project. If you are in doubt, choose Microsoft Office 2000 as the minimum supported Office version. If you need background information, see Choosing interop assemblies.

Choose your programming language and the minimum Office version that you want to support and click Next.

The wizard allows creating add-in projects targeting several Office applications. Since we want our plugin to work in Microsoft Word, Excel and PowerPoint, we are selecting these three apps.

Choosing Office applications to support

You can choose one or more Microsoft Office applications in the above window. For every chosen application, the project wizard will do the following:

  • copy the corresponding interop assembly to the Interops folder of your project folder,
  • add an assembly reference to the project
  • add a COM add-in module to the project
  • set up the SupportedApp property of the add-in module
  • add a property to the add-in module; the property name reflects the name of the chosen Office application; you will use that property
  • to access the object model of the Office application loading your add-on, see Step 6. Accessing host application objects.

Select the Office applications you want to support by your add-in and click Next. The wizard allows specifying a strong name file; it is used to uniquely identify your add-in assembly.

Specifying a strong name file

If you don't have a specific strong name key file, choose Generate new. If you are in doubt, choose Generate new. If, later on, you need to use a strong name key file, specify its name on the Signing tab of your project properties; you are required to unregister your project before using another strong name.

Choose Generate new or specify an existing .snk file and click Finish.

The project wizard creates and opens a new solution in Visual Studio.

A new COM add-in project in Visual Studio

The solution contains an only project, the COM add-in project. The project contains the AddinModule.vb file (for VB.NET projects) or AddinModule.cs (for C# projects) discussed in the next step.

Step 2. Add-in module

AddinModule.vb (or AddinModule1.cs) is the core part of the add-in project. It is a container for components essential for the functionality of your plugin. You configure the addin's settings in the module's properties, put components onto the module's designer, and write the functional code of your add-in in this module. To review its source code, in the Solution Explorer, right-click the AddinModule1.vb (or AddinModule1.cs) file and choose View Code in the popup menu.

COM add-in module

In the code of the module, pay attention to three points:

  • Comment line in the constructor of the module

The text suggests that you write initialization code in the AddinInitialize or AddinStartupComplete events of the add-in module, not in the constructor. This is important because an instance of the module is created (this runs the constructor) when your plug-in is being registered and unregistered. When the module is created for this purpose, no Office objects, properties, methods or events are available. If your code is not prepared for this, the installer of your add-in will fail.

Moving custom initialization code out of the module's constructor allows preventing installation failures.
  • ExcelApp, WordApp, and PowerPointApp properties

You use these properties – they are generated by the COM add-in project wizard – as entry points to the object models of the corresponding Office applications; see Step #6 - Accessing host application objects.

  • CurrentInstance property

This property returns the current instance of the add-in module, a very useful thing if you need to access the add-in module from e.g. a task pane.

Step 3. Add-in module designer

The designer of the add-in module allows setting add-in properties and adding components to the module.

In Solution Explorer, right-click the AddinModule.vb (or AddinModule.cs) file and choose View Designer in the popup menu.

COM Add-in designer

The add-in module designer view provides access to the following four areas shown in the screenshot below:

COM Add-in module

  • Add-in Express Toolbox - (#1 on the screenshot above) it contains commands; clicking a command creates a new Add-in Express component and places it onto the add-in module.
  • Add-in module designer - (#2 on the screenshot above) it is a usual designer.
  • In-place designer - (#3 on the screenshot above) if there's a visual designer for the currently selected Add-in Express component, then it is shown in this area.
  • Help panel - see #4 in the screenshot above.

To put any Add-in Express component onto the module, you click an appropriate command in the Add-in Express Toolbox (#1 in the screenshot above). Then you select the newly created component and set it up using the visual designer (#3 in the screenshot above) and Properties window.

Note that the add-in module provides a number of properties. Click the designer surface and specify the name and description of your add-on in the Properties window. Also, pay attention to the RegisterForAllUsers property - it is essential for distinguishing per-user and per-machine COM add-ins; you must unregister the add-in project before modifying this property.

Step 4. Creating a new Office toolbar

In the Add-in Express Toolbox, click the Add ADXCommandBar button. This places a new ADXCommandBar component onto the add-in module. Select the ADXCommandBar just created and specify the toolbar name in the CommandBarName property (see in the Properties window).

Creating a new command bar

You may use both Command Bar UI and Ribbon UI components on the add-in module. When your add-in is loaded in a particular version of the host application, either command bar or ribbon controls will show up. Find additional information in Command Bars in the Ribbon UI.

ADXCommandBar creates controls on the toolbar the name of which you specify in the CommandBarName property. If the specified toolbar is missing on the host application, ADXCommandBar creates it. That is, if you place some Add-in Express CommandBar control components onto the ADXCommandBar the CommandBarName property of which is set to "Standard", this will create the controls on the built-in Standard toolbar, while specifying CommandBarName = "Standard2" will create a new toolbar, Standard2, with the controls on it. If the Standard2 toolbar exists in the host application, the buttons will be added to that toolbar. You can use our free Built-in Controls Scanner to get the names of all built-in command bars in any Office application.

Put a CommandBar component onto the add-in module

Step 5. Creating a new toolbar button

Select the command bar component on the designer of the add-in module and expand the in-place designer area. In this area, you'll see the visual designer of the ADXCommandBar component. Use the visual designer to put a toolbar button onto the command bar component.

Command bar component

Adding a new button to an MS Office toolbar

To achieve the result shown in the screenshot above, select the new button and open the Properties window where you specify the button's Caption property and add an event handler to the Click event. Also, in the screenshot above, we demonstrate the properties that make the icon visible and transparent: Image, ImageList, and ImageTransparentColor. Please pay attention: to get the icon displayed, the Style property (it isn't visible in the screenshot) is set to adxMsoButtonIconAndCaption. This is because command bar buttons do not show icons by default. To get the icon transparent, the value of the ImageTransparentColor property is chosen in accordance with the bitmap used. See also Command bar control properties and events.

Step 6. Accessing host application objects

The add-in module provides the HostApplication property that returns the Application object (of the Object type) of the host application the plug-in is currently running in. The project wizard adds properties such as ExcelApp, WordApp, etc. to the module; the properties just cast HostApplication to the appropriate type. You use these properties as entry points to the corresponding object models:


Private Sub DefaultAction(ByVal sender As System.Object) _
    Handles AdxCommandBarButton1.Click
    MsgBox(GetInfoString())
End Sub

Friend Function GetInfoString() As String
    Dim ActiveWindow As Object = Nothing
    Try
        ActiveWindow = Me.HostApplication.ActiveWindow()
    Catch
    End Try
    Dim Result As String = "No document window found!"
    If Not ActiveWindow Is Nothing Then
        Select Case Me.HostType 
            Case ADXOfficeHostApp.ohaExcel
                Dim ActiveCell As Excel.Range = _
                    CType(ActiveWindow, Excel.Window).ActiveCell
                If ActiveCell IsNot Nothing Then
                    'relative address
                    Dim Address As String = ActiveCell.AddressLocal(False, False)
                    Marshal.ReleaseComObject(ActiveCell)
                    Result = "The current cell is " + Address
                End If
            Case ADXOfficeHostApp.ohaWord
                Dim Selection As Word.Selection = _
                    CType(ActiveWindow, Word.Window).Selection
                Dim Range As Word.Range = Selection.Range
                Dim Words As Word.Words = Range.Words
                Dim WordCountString = Words.Count.ToString()
                Marshal.ReleaseComObject(Selection)
                Marshal.ReleaseComObject(Range)
                Marshal.ReleaseComObject(Words)
                Result = "There are " + WordCountString _
                    + " words currently selected"
            Case ADXOfficeHostApp.ohaPowerPoint
                Dim Selection As PowerPoint.Selection = _
                    CType(ActiveWindow, PowerPoint.DocumentWindow).Selection
                Dim SlideRange As PowerPoint.SlideRange = Selection.SlideRange
                Dim SlideCountString = SlideRange.Count.ToString()
                Marshal.ReleaseComObject(Selection)
                Marshal.ReleaseComObject(SlideRange)
                Result = "There are " + SlideCountString _
                    + " slides currently selected"
            Case Else
                Result = AddinName + " doesn't support " + HostName
        End Select
        Marshal.ReleaseComObject(ActiveWindow)
    End If
    Return Result
End Function
               

Two things in the code above deserve your attention. First, Me.HostApplication.ActiveWindow() is wrapped in a try/catch block: this prevents a notorious exception which occurs when you call ActiveWindow() on the Word.Application object and there are no documents opened in Word. Second, you have to release every COM object created in your code, see Releasing COM objects for more details.

Step 7. Customizing Office main menu

Add-in Express provides a component to customize the main menu of a pre-Ribbon Office application. Note that some Office applications from Office 2003, XP and 2000 have several main menus. Say, in these Excel versions, you find Worksheet Menu Bar and Chart Menu Bar. Naturally, starting from Excel 2007, these menus are replaced with the Ribbon UI. Nevertheless, the CommandBar objects representing the main menus are still accessible programmatically and you may want to use this fact in your code. As for customizing main menus in Outlook, see Step 8. Customizing main menu of Outlook 2007 - 2000.

Main menu component

In this sample, we are going to customize the File menu in Excel and Word, version 2003-2000. You start with adding two main menu components and specifying correct host applications in their SupportedApp properties. Then, in the CommandBarName property, you specify the name of the main menu to be customized.

The screenshot below shows how you set up the main menu component in order to customize the Worksheet Menu Bar main menu in Excel 2003-2000.

Setting up the Main Menu component

Now you can open the in-place designer for the main menu component and populate it with controls.

In-place designer for the main menu component

In the screenshot above, you see the ADXMainMenu component and its visual designer. You use the visual designer to populate the ADXMainMenu with controls. Note that only command bar buttons and command bar popups can be added onto a main menu.

To add a custom control to the File menu, you add a popup control to the ADXMainMenu component and set its Id property to 30002. Specifying anything but 1 in this property means that controls added to that ADXCommandBarPopup component, will be created on a built-in popup with the corresponding ID. And 30002 is the ID of the File menu item in pre-Ribbon Office applications.

To find this and similar IDs, use our free Built-in Control Scanner. For background info please see Connecting to existing command bar controls.

Then you add a button and set their properties in the way described in Step 5. Adding a new toolbar button.

Pay attention to the BeforeID property of the button component. To place the button before the New button, you set this property to 3, which is the ID of the button New. Please remember that showing an image for any command bar control requires choosing a correct value for the Style property of the button. For the newly created menu item (button) set Style = adxMsoButtonIconAndCaption.

See also Step 11. Customizing the Ribbon user interface for customizing the Office button menu in Office 2007 and the File tab (Backstage View) in Office 2010 - 2019.

Step 8. Customizing Office context menus

Add-in Express allows customizing commandbar-based context menus with the ADXContextMenu component. Its use is similar to that of the ADXMainMenu component. See how to set up such a component to add a custom button to the Cell context menu in Excel:

  • Put a commandbar-based context menu component onto the add-in module

Put a Context Menu component onto the add-in module

  • Specify the host application and the name of the context menu to customize

Setting up the Context Menu component

  • Use the in-place designer to add custom controls to the Controls collection of the component

Context menu designer

There are several issues related to using command bar based context menus:

  • Excel contains two different context menus named Cell. This fact breaks down the command bar development model because the only way to recognize two command bars is to compare their names. This isn't the only exception: use our Built-in Control Scanner to find a number of examples. In this case, the context menu component cannot distinguish context menus. Accordingly, it connects to the first context menu of the name specified by you.
  • Command bar based context menu items cannot be positioned in Ribbon-based context menus of Office 2010 - 2019: a custom context menu item created with the ADXContextMenu component will always be shown below any built-in and custom context menu items in a Ribbon-based context menu.

To add a custom item to a ribbon-based context menu, you use the ADXRibbonContextMenu component.

Ribbon context menu component

Unlike its commandbar-based counterpart (ADXContextMenu), this component allows adding custom Ribbon controls to several context menus in the specified Ribbons. The screenshots below demonstrate component settings required for adding a control to the ExcelWorkbook Ribbon. To specify the context menus, to which the control will be added, you use the editor of the ContexMenuNames property of the component.

Ribbon context menu properties

Ribbon context menu names


See also Step 11. Customizing the Ribbon User interface.

Step 9. Handling host application events

The add-in module designer provides the Add Events command that creates (and deletes) event components that allow handling application-level events (see Application-level events).

Selecting event components

With the event components, you handle any application-level events of the host application. Say, you may want to disable the button when a window deactivates and enable it when a window activates. The code is as follows:


   Private Sub Deactivate(ByVal sender As Object, _
      ByVal hostObj As Object, ByVal window As Object) _
      Handles adxWordEvents.WindowDeactivate, _
          adxExcelEvents.WindowDeactivate, _
          adxPowerPointEvents.WindowActivate
      Me.AdxCommandBarButton1.Enabled = False
   End Sub

   Private Sub Activate(ByVal sender As Object, ByVal hostObj As Object, _
      ByVal window As Object) _
      Handles adxWordEvents.WindowActivate, _
          adxExcelEvents.WindowActivate, _
          adxPowerPointEvents.WindowDeactivate
      Me.AdxCommandBarButton1.Enabled = True
   End Sub

Step 10. Handling Excel worksheet events

Add-in Express provides the Excel Worksheet Events Class item in the Add New Item dialog in Visual Studio. A descendant of this class allows connecting to an Excel.Worksheet object and handling its events. You can use it for creating a set(s) of business rules for handling specific Excel worksheets.

Excel Worksheet event template

Selecting the Excel Worksheet Events Class item and clicking OK adds an event class to your project.

Excel worksheet event class

In the event class, add the following code to the procedure that handles the BeforeRightClick event of the Worksheet class:


   Public Overrides Sub ProcessBeforeRightClick(ByVal Target As Object, _
         ByVal E As AddinExpress.MSO.ADXCancelEventArgs)
      Dim R As Excel.Range = CType(Target, Excel.Range)
      'Cancel right-clicks for the first column only
      If R.Address(False, False).IndexOf("A") = 0 Then
         MsgBox("Context menu will not be shown!")
         E.Cancel = True
      Else
         E.Cancel = False
      End If
   End Sub

In addition, you modify the Activate and Deactivate procedures as follows:


   Dim MyEventClass As ExcelWorksheetEventsClass1 = _
       New ExcelWorksheetEventsClass1(Me)
...
Private Sub Deactivate(ByVal sender As Object, ByVal hostObj As Object, _
   ByVal window As Object) _
   Handles adxWordEvents.WindowDeactivate, adxExcelEvents.WindowDeactivate
   Me.AdxCommandBarButton1.Enabled = False
   Select Case Me.HostName
      Case "Excel"
         If MyEventClass.IsConnected Then MyEventClass.RemoveConnection()
      Case "Word"
      Case "PowerPoint"
      Case Else
         MsgBox(Me.AddinName + " doesn't support " + Me.HostName)
   End Select
End Sub

Private Sub Activate(ByVal sender As Object, ByVal hostObj As Object, _
   ByVal window As Object) _
   Handles adxWordEvents.WindowActivate, adxExcelEvents.WindowActivate
   Me.AdxCommandBarButton1.Enabled = True
   Select Case Me.HostName
      Case "Excel"
         If MyEventClass.IsConnected Then MyEventClass.RemoveConnection()
         MyEventClass.ConnectTo(Me.ExcelApp.ActiveSheet, True)
      Case "Word"
      Case "PowerPoint"
      Case Else
         MsgBox(Me.AddinName + " doesn't support " + Me.HostName)
   End Select
End Sub


Step 11. Customizing the Ribbon User interface

To add a new tab to the Ribbon, you use the Add Ribbon Tab command on the Add-in Express Toolbox; it places a new ADXRibbonTab component onto the module. Select the component and, in the in-place designer, use toolbar buttons or context menu to add or delete components that create the Ribbon interface of your addin.

Add Ribbon Tab component

In this sample, you change the caption of your tab to My Ribbon Tab. Then, you add a Ribbon group, and change its caption to My Ribbon Group. Finally, you select the group, add a button and set its caption to My Ribbon Button. Use the Glyph property to set the image for the button.

Ribbon Tab component

Now add an event handler to the Click event of the button and write the following code:


    Private Sub AdxRibbonButton1_OnClick(ByVal sender As System.Object, _
        ByVal control As AddinExpress.MSO.IRibbonControl, _
        ByVal pressed As System.Boolean) Handles AdxRibbonButton1.OnClick
        AdxCommandBarButton1_Click(Nothing)
    End Sub

The sample project described here creates a custom Ribbon tab. You can also customize a built-in Ribbon tab, please check Referring to built-in ribbon controls.

In the code of this sample plugin, you can find how you can customize the Office Button menu in Office 2007, see component named AdxRibbonOfficeMenu1. As to the Backstage View, also known as the File Tab in Office 2010, the sample project provides the AdxBackstageView1 component that implements the customization shown in Figure 3 at Introduction to the Office 2010 Backstage View for developers. Note, if you customize the Office Button menu only, Add-in Express maps your controls to the Backstage View when the plugin is loaded by Office 2010. If, however, both Office Button menu and File tab are customized at the same time, Add-in Express ignores custom controls you add to the Office Button menu. See also Ribbon UI components.

Step 12. Creating advanced task panes in Excel 2019 - 2000

Creating a new Excel task pane includes the following steps:

  • Use the Add-in Express Toolbox to put an Excel Task Panes Manager (ADXExcelTaskPanesManager) onto the add-in module.

  • Excel Task Panes Manager

  • Open the Add New Item dialog in Visual Studio to add an Add-in Express Excel Task Pane, ADXExcelTaskPane, to the project.

  • Creating custom Excel task pane

  • Select the Excel Task Panes Manager component, and add an item to its Items collection(see the screenshot below).

  • Creating custom Excel task pane

Select the newly created item and, in the Properties window, specify properties as follows:

  • AlwaysShowHeader - specifies that the pane header will be shown even if the pane is the only pane in the current region (optional).
  • CloseButton - specifies if the Close button will be shown in the pane header. Obviously, there's not much sense in setting this property to true when the header isn't shown. (optional)
  • Position - specifies the region in which an instance of the pane will be shown. Excel panes are allowed in four regions docked to the four sides of the main Excel window: Right, Bottom, Left, and Top. The fifth region is Unknown. In this add-in, we use Position=Bottom.
  • TaskPaneClassName - specifies the class name of the Excel task pane.

Creating custom Excel task pane

Now you add a label onto the form and change its caption in the following code:

Private Sub RefreshTaskPane()
    Private Sub RefreshTaskPane()
    Select Case Me.HostName
        Case "Excel"
            Dim Pane As ADXExcelTaskPane1 = _
                TryCast(Me.AdxExcelTaskPanesCollectionItem1.TaskPaneInstance, _
                    ADXExcelTaskPane1)
            If Pane IsNot Nothing Then
                Pane.Label1.Text = Me.GetInfoString()
            End If
        Case "Word"
        Case "PowerPoint"
        Case Else
            'System.Windows.Forms.MessageBox.Show("Invalid host application!")
    End Select
End Sub

See also Advanced custom task panes

Step 13. Creating advanced task panes in PowerPoint 2019 - 2000

Now you create a PowerPoint task pane:

  • Use the Add-in Express Toolbox to put a PowerPoint Task Panes Manager (ADXPowerPointTaskPanesManager) onto the add-in module.

  • PowerPoint Task Panes Manager

  • Open the Add New Item dialog in Visual Studio to add an Add-in Express PowerPoint Task Pane, ADXPowerPointTaskPane, to the project.

  • Add PowerPoint Pane

  • Select the PowerPoint Task Panes Manager component and add an item to its Items collection (see the screenshot below).

Setup the Advanced PowerPoint Pane

Select the newly created item and, in the Properties window, specify properties as follows:

  • AlwaysShowHeader - specifies that the pane header will be shown even if the pane is the only pane in the current region (optional).
  • CloseButton - specifies if the Close button will be shown in the pane header. Obviously, there's not much sense in setting this property to true when the header isn't shown. (optional)
  • Position - specifies the region in which an instance of the pane will be shown. Excel panes are allowed in four regions docked to the four sides of the main Excel window: Right, Bottom, Left, and Top. The fifth region is Unknown. In this add-in, we use Position=Bottom.
  • TaskPaneClassName - specifies the class name of the Excel task pane.

Setup the Advanced PowerPoint Pane, part 2

Now add a label onto the form, write a property that reads and updates the label, and update RefreshTaskPane in order to set the property value:


Private Sub RefreshTaskPane()
    Select Case Me.HostName
        Case "Excel"
...
        Case "Word"
        Case "PowerPoint"
            Dim Pane As ADXPowerPointTaskPane1 = _
                TryCast( _
                    Me.AdxPowerPointTaskPanesCollectionItem1.TaskPaneInstance, _
                    ADXPowerPointTaskPane1)
            If Pane IsNot Nothing Then
                Pane.Label1.Text = Me.GetInfoString()
            End If
        Case Else
            'System.Windows.Forms.MessageBox.Show("Invalid host application!")
    End Select
End Sub

Step 14. Creating advanced task panes in Word 2019 - 2010

You create a Word task pane in the same manner:

  • Use the Add-in Express Toolbox to put a Word Task Panes Manager (ADXWordTaskPanesManager) onto your add-in module.

  • Word Task Panes Manager

  • Open the Add New Item dialog in Visual Studio to add an Add-in Express Word Task Pane (ADXWordTaskPane) to the project.

  • Word Task Pane

  • Select the Word Task Panes Manager component, add an item to its Items collection, bind the pane to the item and specify an appropriate value in the Position property.

Set Word Task Pane up

Set Word Task Pane up, part 2

Now add a label onto the form and update RefreshTaskPane in order to set the label:


Private Sub RefreshTaskPane()
    Select Case Me.HostName
        Case "Excel"
...
        Case "Word"
            Dim Pane As ADXWordTaskPane1 = _
                TryCast( _
                    Me.AdxWordTaskPanesCollectionItem1.CurrentTaskPaneInstance, _
                    ADXWordTaskPane1)
            If Pane IsNot Nothing Then
                Pane.Label1.Text = Me.GetInfoString()
            End If
        Case "PowerPoint"
...
        Case Else
            'System.Windows.Forms.MessageBox.Show("Invalid host application!")
    End Select
End Sub

The different names of the properties returning instances of the three pane types reflect the difference in Excel, PowerPoint and Word windowing; while Excel and PowerPoint show their documents in just one main window, Word normally shows documents in multiple windows. In this situation, the Word Task Panes Manager creates one instance of the pane for every document open in Word. Therefore, you need to handle the task pane instance, which is currently active. For that reason, the property name is CurrentTaskPaneInstance.

Step 15. Running the COM Add-in

Choose Register Add-in Express Project in the Build menu. Alternatively, you can choose Add-in Express | Register in the context menu of the add-in project. See also If you use an Express edition of Visual Studio.

Register COM add-in from the IDE

Start the host application(s) and check if the add-in works. If the add-in isn't visible in the host application's UI, see Troubleshooting add-in loading.

The newly created COM add-in in Microsoft Word:

COM add-in in Word

The COM add-in in Microsoft Excel:

COM add-in in Excel

The COM add-in in Microsoft PowerPoint:

COM add-in in PowerPoint

You can also find your add-in in the COM Add-ins dialog.

Step 16. Debugging the COM add-in

To debug your add-in, in the Project Options window, specify the path to the host application of the add-in in Start External Program and run the project.

Debugging a COM add-in

Step 17. Deploying the COM add-in

The table below provides links to step-by-step instructions for deploying Office add-ins. Find background information in Deploying Office extensions.

Table 1. Deploying COM add-ins: links to step-by-step instructions

How you install the Office extension

Per-user COM add-in
Installs and registers for the user running the installer

Per-machine COM add-in
Installs and registers for all users on the PC

A user runs the installer from a CD/DVD, hard disk or local network location. Windows Installer
ClickOnce
ClickTwice :)
Windows Installer
ClickTwice :)
A corporate admin uses Group Policy to install your Office extension for a specific group of users in the corporate network; the installation and registration occurs when a user logs on to the domain. Windows Installer N/A
A user runs the installer by navigating to a web location or by clicking a link. ClickOnce
ClickTwice :)
ClickTwice :)

What's next?

Here you can download the project described above, both VB.NET and C# versions; the download link is labeled Add-in Express for Office and .NET sample projects.

You may want to check the following sections under Add-in Express tips and notes: