Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to add items to splitbuttons and galleries. The issue is with the Factory. In the following OfficeRibbon code file Factory is unknown. It is also unknown in the addin code file. I am missing a reference somewhere. I have also tried Globals.Factory still unknown.

RibbonButton rc = this.Factory.CreateRibbonButton(); 

I have the following using statements.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Tools.Ribbon;
//using Microsoft.Office.Tools.Excel.Extensions;

This code also fails in the ThisAddin.cs which has been renamed to ReqCommon.cs in my project.

My desired end goal is to dynamically add items to these two controls. Examples i have found here and elsewhere all seem predicated on this elusive Factory.

The project does reference Microsoft.Office.Tools.Common.v9.0.dll

If you are using the Ribbon Designer - it will automatically create this Factory for you (Globals.Factory.GetRibbonFactory()) - otherwise you need to create your own Factory by overriding CreateRibbonExtensibilityObject() in ThisAddin.cs (your ReqCommon.cs)

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    Ribbon1 tempRibbon = new Ribbon1();
    tempRibbon.tab1.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office;
    tempRibbon.tab1.ControlId.OfficeId = "TabHome";
    return Globals.Factory.GetRibbonFactory().CreateRibbonManager(new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { tempRibbon });   

The Ribbon Designer inherits from Ribbon.RibbonBase which contains the property RibbonBase.Factory which enables this.Factory to be used within it.

In case I broke the project, I created a new Excel addin in VS2010 added a ribbon(not XML). Then tried your code: Factory and IRibbonExtension cannot resolve. I have followed the links you provided and it looks like it should work. I don't know why this is different. If any of this matters, I have VS2010 ultimate, office 2010 64bit, on Win7 Pro. – Joe Johnston Aug 17, 2012 at 15:19 For IRibbonExtension, you must be missing a reference to Office.dll - C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office12\Office.dll. For Factory, you must be missing a reference to Microsoft.Office.Tools.Excel.dll from C:\Program Files\Reference Assemblies\Microsoft\VSTO40\v4.0.Framework\Microsoft.Office.Tools.Excel.dll – SliverNinja - MSFT Aug 17, 2012 at 16:49 Not with .NET 3.5 Factory doesn't exist in the 3.5 version. I was able to get this to work with @SilverNinja's method. In order to do it I created a new .NET 4.0 Office Addin. This is key. – Joe Johnston Aug 20, 2012 at 13:46 Great catch and thanks for posting back! It seems Factory was added in VSTO 4 codebase and is not present in VSTO 3. As proof... RibbonBase's other versions do not go back past VS 2010. – SliverNinja - MSFT Aug 20, 2012 at 13:58 Additional info: The visual ribbon designers do not appear to be compatable. :( Simply switching the target .NET version from 3.5 to 4.0 will not yield positive results. IMO the best course of action is: Recreate a new 4.0 addin from the Visual Studio template and bring your code forward. – Joe Johnston Aug 20, 2012 at 14:22

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.