Ribbon - custom button calls macro with argument

P

Paul Martin

Hi guys

In XL2003 with custom toolbars, I could assign an OnAction macro with
an argument, something like .OnAction = "'MyMacro "SomeArgumentHere"'"

From memory, the argument is wrapped in double quotes, the entire
macro and argument is wrapped in single quotes and double quotes
around that. It might have been slightly different, but you get the
idea.

What I'm trying to do now is, in XL2007, customise the ribbon
similarly. But the syntax in XML is different and I'm wondering how
you wrap the argument. Any suggestions are appreciated.

Thanks in advance

Paul Martin
Melbourne, Australia
 
A

Andy Pope

Hi,

Can you make use of the Tag property of the button control?

The onaction callback for the button would be

Public Sub Button1_onAction(control As IRibbonControl)
'
' Code for onAction callback. Ribbon control button
'
MsgBox control.Tag

End Sub

But I think your real problem would be the xml is not dynamic, where as your
code example is.
So perhaps the passed argument is not relevant in xl2007 as you will have to
have some other way of handling the dynamic argument. Such as storing the
argument in a public variable. and testing that in the onAction callback.

Cheers
Andy
 
P

Paul Martin

Thanks for the reply Andy, though I don't fully understand your
suggestion. What I'm trying to do is capture the user's selection in
a combobox and use that selection as the criteria for what a procedure
performs. Any suggestions?

Thanks in advance

Paul
 
A

Andy Pope

Hi,

So if I understand, you have a button that will run different macros
depending upon the current selected item of a dropdown control.
In which case you need to use a call back to get the dropdown item.

vba code.
Public Sub Dropdown1_onAction(control As IRibbonControl, id As String, index
As Integer)
'
' Code for onAction callback. Ribbon control dropDown
'
MsgBox "You selected ID=" & id & vbLf & "Index=" & index, vbInformation,
"onAction Callback"

End Sub

xml for new group on home tab. Dropdown has 3 items, Cat, Dog and Fish.

<!--RibbonX Visual Designer 1.6 for Microsoft Excel. XML Code produced on
2009/11/18-->
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
<ribbon >
<tabs >
<tab idMso="TabHome" >
<group
id="Group1"
label="Group1">
<dropDown
id="Dropdown1"
label="Pick Me"
getItemLabel="Dropdown1_getItemLabel"
onAction="Dropdown1_onAction">
<item
id="itmCat"
label="Cat"/>
<item
id="itmDog"
label="Dog"/>
<item
id="itmFish"
label="Fish"/>
</dropDown >
</group >
</tab >
</tabs >
</ribbon >
</customUI >

Cheers
Andy
 
P

Paul Martin

Thanks Andy. I'm actually working through your Ribbon Add-In, which
looks very useful. I'll post back if I get stuck. Thanks again.

Paul
 
P

Paul Martin

FWIW, I didn't really like the idea of using the Tag property.
Initially it looked like a quick-fix, but an unnecessary one. Having
selected a dropdown item, surely there's a way of capturing that
selection without having to double-handle the value by entering it in
the XML as a Tag property.

My dropdowns are populated by values in cell ranges so, given that the
dropdown captures the selection's index (base 0), I can use index + 1
as the pointer to the cell in the range. Hopefully that might assist
someone who is searching for a solution to my problem.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top