Getting a Dropdown to Work in a Customised Excel Ribbon

Statto

New Member
Joined
Jul 2, 2014
Messages
6
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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

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
Back
Top