I'm trying to make two word add-ins' groups to appear in the same tab (Tools) but they both create unique tabs (there's two 'Tools' tabs). I saw this video but I'm using the Visual Designer, not XML.
Can I edit the designer code in some way to make this work?
http://blogs.msdn.com/b/vsto/archive/2008/03/10/share-a-ribbon-customization-between-office-applications.aspx
Office 2007
Create the Ribbon
Create a Class Library Project
Consume the Ribbon Customization
Add the following code to the ThisAddin, ThisWorkbook, or ThisDocument class of your project. This code overrides the CreateRibbonExtensibilityObject method and returns the Ribbon to the Office application.
protected override Microsoft.Office.Core.IRibbonExtensibility
CreateRibbonExtensibilityObject()
{
return new Microsoft.Office.Tools.Ribbon.RibbonManager(
new Microsoft.Office.Tools.Ribbon.OfficeRibbon[] { new
SharedRibbonLibrary.Ribbon1() });
}
Add a new class to the project. Accept the default name “Class1.cs”.
Replace the code in the Class1 file with the following:
partial class ThisRibbonCollection : Microsoft.Office.Tools.Ribbon.RibbonReadOnlyCollection
{
internal SharedRibbonLibrary.Ribbon1 Ribbon1
{
get { return this.GetRibbon<SharedRibbonLibrary.Ribbon1>(); }
}
}
Ok – You are done! You can now access the Ribbon and the button that you added to the Ribbon in your code. Lets try by handling an event in the consuming project.
Handle the Button Click Event
Add the following code to the startup event handler of project.
Globals.Ribbons.Ribbon1.button1.Click += new EventHandler<Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs>(button1_Click);
Add the following event handler to your project:
void button1_Click(object sender,
Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs e)
{
System.Windows.Forms.MessageBox.Show("I can handle events!");
}
Run the project.
When the Office application opens, click the Add-Ins tab, and then click your button. A message that says “I can handle events!” appears.
Office 2010 implementation: http://blogs.msdn.com/b/vsto/archive/2010/06/23/sharing-a-ribbon-customization-between-office-projects-in-visual-studio-2010-mclean-schofield.aspx
The 2010 implementation actually add's two Ribbons - one for each Add-In. I believe the article is only applicable to Add-Ins on the same Ribbon in different Office products (eg Word and Excel) not two Excel Add-ins.
The only other avenue I've found is a 3rd party component: http://www.add-in-express.com/creating-addins-blog/2012/11/05/excel-addin-shared-ribbon-tabs/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With