ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ribbon - custom button calls macro with argument (https://www.excelbanter.com/excel-programming/436258-ribbon-custom-button-calls-macro-argument.html)

Paul Martin[_2_]

Ribbon - custom button calls macro with argument
 
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

Paul Martin[_2_]

Ribbon - custom button calls macro with argument
 
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

Andy Pope

Ribbon - custom button calls macro with argument
 
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
--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Paul Martin" wrote in message
...
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



Paul Martin[_2_]

Ribbon - custom button calls macro with argument
 
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

Paul Martin[_2_]

Ribbon - custom button calls macro with argument
 
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


All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com