2

I have an xlam file that I want to add a custom ribbonX buttons to.

I use Custom UI Editor and with this xml it "works".

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
        <tabs>
            <tab id="Tab1" label="LeaveReport">
                <group id="Group1" label="Formatering">
                    <button id="Button1" imageMso="ChartSwitchRowColumn" size="large"/ >
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

But if I add onaction to make the button do something it does not load at all. Meaning the tab and buttons are not there at all.

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
        <tabs>
            <tab id="Tab1" label="LeaveReport">
                <group id="Group1" label="Formatering">
                    <button id="Button1" imageMso="ChartSwitchRowColumn" size="large"/ onAction="formatera_for_pivot_tabell()"/ >
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

I have also tried without ().
What am I doing wrong here? A button without an action is quite useless :-/

Andreas
  • 23,610
  • 6
  • 30
  • 62
  • I found the problem by "luck". There is a xlam called RibbonEditor.xlam that can create the xml code too. And it also have a "vba creator". And that is where I noticed the sub should be called as following: `Public Sub formatera_for_pivot_tabell(control As IRibbonControl)` and not as you usually do: `Sub formatera_for_pivot_tabell()`. I will make an answer of it when I have time. Just posting this so that nobody wastes time on it. – Andreas Oct 02 '17 at 08:03

1 Answers1

1

To get your custom ribbon UI working correctly you must:

  1. Specify the ribbon callback in the ribbon XML without brackets.

    onAction="formatera_for_pivot_tabell"
    
  2. The XML namespace should be updated and look like the following one:

    xmlns="http://schemas.microsoft.com/office/2009/07/customui"

  3. Define the callback in the code-behind file.

    • C#: void OnAction(IRibbonControl control)
    • VBA: Sub OnAction(control As IRibbonControl)
    • C++: HRESULT OnAction([in] IRibbonControl *pControl)
    • Visual Basic: Sub OnAction(control As IRibbonControl)

It should have a signature specified in the following articles:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45