I am using VS 2010 to develop an Excel 2007 COM add-in. Since this is a VS 2010 Office Project, it focuses on the .NET 4.0 client platform. I added a new Ribbon (XML) element called MyRibbon, so the default file names from this file are AdAdInIn.cs, MyRibbon.cs and MyRibbon.xml.
Everything builds perfectly. It is published with the extension .vsto. When I install the add-in (through the provided Setup.exe), it takes Excel as installed and is checked in the list of COM add-ins. It is also designed to be loaded at startup. However, either opening Excel first or opening an Excel file does not add a tab to the ribbon.
I can say that add-ins are loading because it puts the COM add-in in the first cell of the first sheet. It seems that CreateRibbonExtensibilityObject () is not getting the call.
Does anyone have any ideas or can I say how to display error messages that may be buried?
Details below.
I added an override to CreateRibbonExtensibilityObject ():
protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject() { return new MyRibbon(); }
MyRibbon.xml looks like this: three buttons in a group inside a tab:
<?xml version="1.0" encoding="UTF-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load"> <ribbon> <tabs> <tab id="TabAdvComTracking" idMso="TabAdvComTrackingMso" label="Adv.com Tracking"> <group id="groupPrepare" label="Prepare"> <button id="GenerateNewWorkbook" idMso="GenerateNewWorkbookMso" enabled="1" size="large" onAction="GenNewWorkbook" label="Make" /> <separator visible="1"/> <button id="ClearData" idMso="ClearDataMso" enabled="1" size="large" onAction="ClearData" label="Clear" /> </group> <group id="GroupDoIt" idMso="GroupDoItMso" label="Just Do It"> <button id="CaptureIds" idMso="CaptureIdsMso" enabled="1" size="large" onAction="CaptureData" label="Eat" /> </group> </tab> </tabs> </ribbon> </customUI>
MyRibbon.cs looks like this:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using Office = Microsoft.Office.Core; using Excel = Microsoft.Office.Interop.Excel; namespace AdvComTrackingAddIn { [ComVisible(true)] public class MyRibbon : Office.IRibbonExtensibility { private Office.IRibbonUI ribbon; public MyRibbon() { } #region IRibbonExtensibility Members public string GetCustomUI(string ribbonID) {
Finally, ThisAddIn.cs looks like this:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; using Excel = Microsoft.Office.Interop.Excel; using Office = Microsoft.Office.Core; using Microsoft.Office.Tools.Excel; using System.IO; using System.Reflection; namespace AdvComTrackingAddIn { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { Globals.ThisAddIn.Application.get_Range("A1").Value = "COM add-in loaded"; } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { GC.Collect(); } protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject() { return new MyRibbon(); } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } }