8
votes

This is VS2010 + Office 2010 add-in. All I want is to add a button (or button group) to multiple built-in tabs. For example, my buttons should be available in both New Mail Message Ribbon and in New Appointment Ribbon. I have tried adding a new tab (in the Visual Designer) but that doesn't seem to work. The button group appears on the New Mail Message tab, but not on the Appointment tab. BTW, I'm using the following IDs: TabNewMailMessage and TabAppointment.

4

4 Answers

7
votes

For anyone else pulling their hair about this, the only way I was able to see my group on both Appointment and New Mail Message tabs was by adding one Ribbon for each built-in tab, and then copy/pasting all of the UI and code from one Ribbon to the other. Make sure you choose proper RibbonType (a property of your Ribbon) for each built-in tab.

4
votes

The designated answer is now obsolete!

  1. On the OfficeRibbon object, set the RibbonType for as many cases as necessary (e.g. Microsoft.Outlook.Explorer and Microsoft.Outlook.Mail.Read).
  2. Add a first Tab and set the ControlId.OfficeId (e.g. TabMail)
  3. Add another Tab and set the ControlId.OfficeId (e.g. TabReadMessage)
  4. In each Tab add a Group and a Button within and set the Button.Click event to point to the same OnClick method
0
votes

Similar to the answer above but without using XML, you can have the group in two different locations adding a second tab.

In the Ribbon Designer add a second tab to the ribbon and change the ControlID to the second location you would like to see your group. Then right click on the group in the original tab and click copy. Click back over to the new tab and paste the group there. It will copy over anything that is already in the group. You will, however, have to add the events back in. But for me I just re-used the already created events and it works perfectly. CHEERS.

0
votes

I don't have Outlook, but I have used the following in Word/Excel/PPT, so I'm hoping it will work in Outlook as well (untested!).

Try adding an Ribbon (XML) item and then add the two tabs with a button that looks the same and calls the same code but with different IDs.

XML:

<tab idMso="TabNewMailMessage">
    <group id="MyGroup1" label="My Group1">
        <button id="myButton1" label="Button 1" size="large"  onAction="ButtonOnAction" />
    </group>
</tab>
<tab idMso="TabAppointment">
    <group id="MyGroup2" label="My Group2">
        <button id="myButton2" label="Button 2" size="large"  onAction="ButtonOnAction" />
    </group>
</tab>

C#:

    public void ButtonOnAction(IRibbonControl control)
    {
        switch (control.Id)
        {
            case "myButton1":
            case "myButton2":
                // do something
                Console.Out.WriteLine("Button ID: {0}", control.Id);
                break;
        }
    }