Eugene Astafiev

HowTo: Create add-ins for Office 2007, 2010 and 2013 with a shared ribbon tab

Sometimes Microsoft Office developers may need to place the UIs of several add-ins on a single ribbon tab. Just imagine the following scenario: a user wants to install a few COM add-ins from the same vendor. Are they going to get a separate ribbon tab for each add-in’s UI? Frankly speaking, right after Office 2007 and 2010 releases I saw a bunch of add-ins that used separate tabs… But that wasn’t a proper and right solution. What is the Office Ribbon going to look like if a user installs a dozen add-ins?

The Add-in Express Developer Guide provides a tip on Sharing Ribbon controls across multiple add-ins where you can find the required settings for merging ribbon tabs from several Office add-ins into a single one. So, you may ask me now: why do I need to spend my time of reading this article if the documentation already covers the issue? The answer is simple: I would like to guide you in a step-by-step manner because this question is often asked on our forums and email.

How to create a shared ribbon tab for Excel add-ins

In the sample projects, which you can download at the end of the article, I developed two COM add-ins for Excel 2013, 2010 and 2007 with a shared tab and separate groups where the buttons for each add-in reside. For this example I used the latest version of Add-in Express for Office and .net. You can create a shared ribbon tab for any Office add-ins, e.g. Outlook, Word, PowerPoint and other apps in a similar manner.

      1. Create a new COM add-in project and then add the ADXRibbonTab component to the add-in module. Next, set the Shared property of the just added component to true. This is the key property which lets the target host application to know that your ribbon tab is to be shared, i.e. that it belongs to the “shared” namespace.

      Setting the Shared property of the Ribbon Tab component to True

      2. Set the Namespace property of your add-in module. I used the ADXNamespace value:

      Configuring the Namespace property of the add-in module

      3. Add a new ribbon group (ADXRibbonGroup control) to the just added ribbon tab and set up the following properties:

    1. NameadxRibbonGroupPrivate
    2. CaptionAdd-in #1
      4. Add a new ribbon button (ADXRibbonButton control) to the just added ribbon group and set it up:

    1. NameadxRibbonButton
    2. CaptionHello world!
    3. SizeLarge
      5. Add an event handler for the just added ribbon button. Please open the Properties window in Visual Studio and click the lightening icon to see the list of available events:

      Add-in an event handler to the button's OnClick event

      The event handler stub will be generated if you double click the cell next to the event name.

        C# code example:
      private void adxRibbonButton_OnClick(object sender, 
                     IRibbonControl control, bool pressed)
      {
          System.Windows.Forms.MessageBox.Show(this.ToString(),
           "Add-in Express sample add-ins", MessageBoxButtons.OK ,
                                      MessageBoxIcon.Information);
      }
       
      public override string ToString()
      {
          return "The first COM add-in with a shared ribbon tab.";
      }

      Also I have added an image to the button. I will omit the steps on how to add images because they are common for all Add-in Express based add-ins and you can find the required settings in the sample Excel add-ins (C# and VB.NET) at the end of the article.

      6. Add a new Add-in Express based add-in project to the solution. Set the Namespace property of the add-in module to the same value we used on step #2.
      7. Add the ADXRibbonTab component to the add-in module and set its values like this:

    1. NameadxRibbonTabShared
    2. CaptionOur shared tab
    3. Id – copy the value of the ribbon tab’s Id property from my C# Excel add-in (in my example, this value equals to adxRibbonTab_73ba97036a984c86a8b1dce96f64c1b7).
      8. Add a ribbon group control and set its properties:

    1. NameAdxRibbonGroupPrivate
    2. CaptionAdd-in #2
      9. Add a ribbon button control to the ribbon group:

    1. NameAdxRibbonButton
    2. CaptionHi world!
    3. SizeLarge
      10. Add an event handler for the Click event of the ribbon button like we did on step #5:

        VB.NET code example:
      Private Sub AdxRibbonButton_OnClick(ByVal sender As System.Object, _
                       ByVal control As AddinExpress.MSO.IRibbonControl, _
                       ByVal pressed As System.Boolean) Handles AdxRibbonButton.OnClick
          MsgBox(Me.ToString(), MsgBoxStyle.Information, "Add-in Express sample add-ins")
      End Sub
       
      Public Overrides Function ToString() As String
          Return "Our second COM add-in with a shared ribbon tab."
      End Function
      11. Now you can register both add-ins and see the following message boxes in Excel:

      The message displayed by the C# add-in in Excel 2010

      If you click the button of the second add-in, you will see a similar message:

      The message displayed by the VB.NET add-in in Excel 2010

Have a good week and see you next week ;-)

Available downloads:

These sample COM Add-ins were developed using Add-in Express for Office and .net:
C# Excel add-in with a shared tab
VB.NET Excel add-in with a shared tab

4 Comments

  • http://0.gravatar.com/avatar/0879b431ac926a3a5cab8c43a1e9645c?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Reinhardt says:

    Hi Eugene,

    thank you for your post about sharing ribbon tabs across multiple add-ins. It works very fine.

    Is it possible to do the same with AddinAdditionalModules? I tried to do so, but without success as AddinAdditionalModules don’t provide the namespace property fore the “shared” namespace. Is this the only reason?

    I would like to combine the benefits of your post with those of Pieter van der Westhuizen’s post: “Creating modular Office add-ins using Add-in Express”. Pieter has helped me a lot to get the modular approach working.

    The backround: over years I have written a “modular” solution for office 2003 that is splitted in multiple Excel-“.xla”-Addins. The reason for buying Add-in Express was to transform the solution to Visual Basic .Net.

    The solution will exist of several editions. There will be one main module (AddinModule) with the common stuff and several additional modules (AddinAdditionalModules) with the specific code and forms. But I don’t want to create a ribbon tab for every single additional module.
    The main module is expected to provide the shared “master” ribbon tab; all other modules shall share this ribbon tab.

    I use Add-In Express Professional 7.0 and Visual Studio 2010 Professional. I would like to transform my “old” solution to Microsoft Office 2007 and 2010.

    Thanks and kind regards,
    Reinhardt

  • Hi Reinhardt,

    Please take a look at the How to merge several Office add-in projects into one binary article. Is it what you are looking for?

  • http://0.gravatar.com/avatar/e1b0fceec5fdce349bc5666b19c25ff9?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G sersoft says:

    hi
    I’m a beginner developer and i want to create a simple project :
    the project is to make a button in the office ribbon using vb.net 2008 (VSTO) so when i press the button the current docx file goes to a specific folder (ex:(c:\folder)and his name become the current date like that 06.04.2013.docx and the last thing that i want the file goes directly without the savefiledialog appears
    thank you :)

  • Hello Youssef,

    You can use Document.SaveAs to save the current document to a location of your choice; the SaveAs method also allows you to give the document a required name. I have just sent you an email with more details.

Post a comment

Have any questions? Ask us right now!