I have been working on Office Integration over the last few months, and what started off as a Word 2007 add-in has now also expanded to PowerPoint and Excel. I refactored the code and pulled the existing Ribbon into a shared class library for the different VSTO projects to use.

Here’s how I did it:

  1. Create a new class library project called: MyAddin.Common
  2. Add references to:
    • Microsoft.Office.Tools.Common.v9.0
    • Microsoft.Office.Tools.v9.0
    • Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0
  3. Copy the existing ribbon files into VSTO.Common (or if youre starting a fresh, then add a new Office Ribbon)
  4. Set all the buttons and controls modifiers to Public (this will allow you to access these buttons from the other projects)
  5. Add a reference to MyAddin.CommonIn your Office Add-in project
  6. Open the ThisAddin.cs file
  7. Override the CreateRibbonExtensibilityObject method like below
public partial class ThisAddIn
{
 
	OfficeRibbon _myRibbon = new MyOfficeRibbon();

	protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
	{
		return new Microsoft.Office.Tools.Ribbon.RibbonManager(
			new Microsoft.Office.Tools.Ribbon.OfficeRibbon[] { _myRibbon });
	}
 
}

Do the same for the other VSTO Add-in projects.

Comment