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:
- Create a new class library project called: MyAddin.Common
- Add references to:
- Microsoft.Office.Tools.Common.v9.0
- Microsoft.Office.Tools.v9.0
- Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0
- Copy the existing ribbon files into VSTO.Common (or if youre starting a fresh, then add a new Office Ribbon)
- Set all the buttons and controls modifiers to Public (this will allow you to access these buttons from the other projects)
- Add a reference to MyAddin.CommonIn your Office Add-in project
- Open the ThisAddin.cs file
- 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.