Ribbon not showing

212 views
Skip to first unread message

Forna

unread,
Oct 25, 2016, 7:22:04 AM10/25/16
to Excel-DNA
Hello,

I am able to display an Excel DNA menu with this directive above my method:
[ExcelCommand(MenuName = "MyMenu", MenuText = "Execute query")]

but I would like to replace that with a ribbon button. 
I have copied the below code from some samples and pasted it into my project.
Unfortunately nothing happens: no ribbon, no error.

Is there some additional step required to make it work?

[ComVisible(true)]
public class MyRibbon : ExcelRibbon
{
    private static IRibbonUI _ribbonUi;

    // This ribbon xml can be returned in code, or placed in the .dna file
  public override string GetCustomUI(string uiName)
    {
        return
        @"
    <customUI onLoad='Ribbon_Load' xmlns='http://schemas.microsoft.com/office/2006/01/ customui'> 
      <ribbon> 
        <tabs> 
          <tab idMso='TabAddIns'> 
            <group id='group1' label='Group1'> 
              <button id='button1' getEnabled='btn_GetEnabled' getLabel='btn_GetLabel' /> 
            </group> 
          </tab> 
        </tabs> 
      </ribbon> 
    </customUI> 
    ";
    }
    public void Ribbon_Load(IRibbonUI sender)
    {
        _ribbonUi = sender;
    }
    public bool btn_GetEnabled(IRibbonControl control)
    {
        return true;
    }
    public string btn_GetLabel(IRibbonControl control)
    {
        return "My Button";
    }
    public static void Refresh()
    {
        if (_ribbonUi != null) { _ribbonUi.Invalidate(); }
    }
}

Thank you

Govert van Drimmelen

unread,
Oct 25, 2016, 7:57:45 AM10/25/16
to exce...@googlegroups.com

You have a space (before customui) in the xmlns attribute of the xml you show.

With that fixed, it works fine on my machine.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Govert van Drimmelen

unread,
Oct 25, 2016, 8:02:32 AM10/25/16
to exce...@googlegroups.com

Note that you can enable error reporting for such errors in the xml, by enabling the option “Show add-in user interface errors”

 

 

Then you’ll see this message with the problematic xml:

 

Forna

unread,
Oct 25, 2016, 9:45:53 AM10/25/16
to Excel-DNA
Thank you Govert for the quick reply.
Since I struggled to find a complete working example, I have posted mine here, it also includes RunTagMacro to call a C# method from the ribbon:

//Ribbon

[ComVisible(true)]
public class MyRibbon : ExcelRibbon
{
   
private static IRibbonUI _ribbonUi;


   
// This ribbon xml can be returned in code, or placed in the .dna file
 
public override string GetCustomUI(string uiName)
   
{
       
return
       
@
"

    <customUI onLoad='Ribbon_Load' xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
      <ribbon>
        <tabs>
          <tab idMso='TabAddIns'>
            <group id='group1' label='Group1'>
              <button getEnabled='btn_GetEnabled' getLabel='btn_GetLabel' size='large' onAction='RunTagMacro' id='Query' tag='btn_Query' />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    "
;

   
}
   
public void Ribbon_Load(IRibbonUI sender)
   
{
        _ribbonUi
= sender;
   
}
   
public bool btn_GetEnabled(IRibbonControl control)
   
{
       
return true;
   
}
   
public string btn_GetLabel(IRibbonControl control)
   
{

       
return control.Id;

   
}
   
public static void Refresh()
   
{
       
if (_ribbonUi != null) { _ribbonUi.Invalidate(); }
   
}

   
// Execute the different actions depending on the button clicked
   
public static void btn_Query()
   
{
       
Query.Create_tables(); //Method call
   
}
}
Reply all
Reply to author
Forward
0 new messages