0

I have two excel-addin project is wroted by C# with excel-dna package and the first add-in have a customui like follow:

<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab id='tab1' label='MyAddIn'>
                <!--Other group-->
            </tab>
        </tabs>
    </ribbon>
    <backstage>
        <tab id='myTab' label='myTab' title='myTabTitle' insertBeforeMso='TabInfo'>
        </tab>
    </backstage>
</customUI>

And the second add-in are more like an extension add-in from the first add-in, it have a customui like follow:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon startFromScratch="false">
        <tabs>
            <tab id="tab1">
                <group id="Report_x" label="Report1">
                    <button id="reports_btn" size="large" label="Reports" onAction="on_api_rpts_btn_click" tag="Report" imageMso="AdpDiagramTableModesMenu"/>
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

Both of two addin loads the customui by using excel-dna package like follow:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using ExcelDna.Integration.CustomUI;

namespace SomeNameSpace
{
    public class MyRibbonClass: ExcelRibbon
    {
        public override string GetCustomUI(string RibbonID)
        {
            string customUiStr = string.empty;
            // read resources
            return customUiStr;
        }
    }
}

But i don't know why i only can see the MyAddIn tab and all group which is definied in the first add-in on Excel ribbon, the second add-in's tab only show in "ExcelOptions" -> "CustomRibbon" -> "Empty Tag" group

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
SKYC
  • 33
  • 6

1 Answers1

1

The idQ property of controls exists to enable multiple add-ins to share containers, such as custom tabs and groups.

In the following VBA example, two Excel add-ins share the same "Contoso" group on the add-ins tab; each adds one button to it. The key is specifying the same unique namespace in the tag. Then, controls can reference this namespace by using idQ.

For the first add-in you could use the following markup:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
  xmlns:x="myNameSpace" >
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group idQ="x:Contoso" label="Contoso">
          <button id="C1" label="Contoso Button 1" size="large" 
            imageMso="FileSave" onAction="c_action1" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

And for the second add-in:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
  xmlns:x="myNameSpace" >
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group idQ="x:Contoso" label="Contoso">
          <button id="C1" label="Contoso Button 1" size="large" 
            imageMso="FileSave" onAction="c_action1" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

If you develop a COM add-in to customize the Fluent UI, the namespace name must be the ProgID value of the COM add-in, but the behavior is otherwise the same (it is recommended).

Note, by default, if a an add-in attempts to manipulate the Microsoft Office user interface (UI) and fails, no error message is displayed. However, you can configure Microsoft Office applications to display messages for errors that relate to the UI. You can use these messages to help determine why a custom ribbon does not appear, or why a ribbon appears but no controls appear. See How to: Show Add-in user interface errors for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • 1
    Awesome!! I set the same `custom xml namespace` in two `customui` xml definition and then set the controls(tab,group) to the same id by using `idQ` then i can merge two `add-in` into a same ribbon tab!! Thank you!! @Eugene Astafiev – SKYC Jun 20 '23 at 03:06