Getting a Dropdown to Work in a Customised Excel Ribbon

Statto

New Member
Joined
Jul 2, 2014
Messages
3
So I'm creating a custom Ribbon using the Office RibbonX Editor and Excel. I want to display a simple dropdown that allows the user to switch between three worksheets.

I'm not sure why it's going wrong, but I keep running into three errors that correspond to the onAction attribute for each item:

Code:
Ln 8, Col 51: The 'onAction' attribute is not declared.
Ln 9, Col 51: The 'onAction' attribute is not declared.
Ln 10, Col 51: The 'onAction' attribute is not declared.

Here is my code:

XML (customUI14.xml file):

XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab id="customTab" label="DropDown" insertAfterMso="TabHome">
                <group id="customGroup" label="Custom Group">
                    
<dropDown id="dropDown1" label="Dropdown Box">
   <item id="dd01" label="Sheet1" imageMso = "_1" onAction="DDOnAction" />
   <item id="dd02" label="Sheet2" imageMso = "_2" onAction="DDOnAction" />
   <item id="dd03" label="Sheet3" imageMso = "_3" onAction="DDOnAction" />
</dropDown>

                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

VBA:

VBA Code:
Sub DDOnAction(control As IRibbonControl, id As String, index As Integer)
    Select Case control.id
        Case "dd01"
            ActiveWorkbook.Sheets("Sheet1").Activate
        Case "dd02"
            ActiveWorkbook.Sheets("Sheet2").Activate
        Case "dd03"
            ActiveWorkbook.Sheets("Sheet3").Activate
    End Select
    
    End Sub
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Dan_W

Active Member
Joined
Jul 11, 2018
Messages
367
Office Version
  1. 365
Platform
  1. Windows
Hi, I had a look at your problem, and your XML code will work if you just move the onAction attributes up into the Dropdown tag, so that the code looks like this:

Rich (BB code):
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
        <tabs>
            <tab id="customTab" label="DropDown" insertAfterMso="TabHome">
                <group id="customGroup" label="Custom Group">                    
                <dropDown id="dropDown1" label="Dropdown Box" onAction="DDOnAction" >
                   <item id="dd01" label="Sheet1" imageMso = "_1" />
                   <item id="dd02" label="Sheet2" imageMso = "_2" />
                   <item id="dd03" label="Sheet3" imageMso = "_3" />
                </dropDown>
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

Then your Callback code should work just fine as you've set it out in your post. Let me know if that helps.
 

Dan_W

Active Member
Joined
Jul 11, 2018
Messages
367
Office Version
  1. 365
Platform
  1. Windows
Sorry, one further amendment - I completely overlooked one line in your code. You need to change:
VBA Code:
Select Case control.id
to
VBA Code:
Select Case id
And then it will work properly.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,499
Messages
5,625,138
Members
416,075
Latest member
TechJosh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top