0

I am trying to get the index value from a custom dropdown on my outlook ribbon. On the dropdown I have added several items and several buttons.

<mso:dropDown id="MydropDown" 
label="SOLV Tickets" 
enabled="true" 
getItemCount="Project1.DDItemCount" 
getItemLabel="Project1.DDListItem"
getSelectedItemIndex="Project1.DDSelctItemIndx"
onAction="Project1.DDOnAction">
    <mso:item id="item" label="Commercial"/>
    ......
    <mso:button id="button1" label="Commercial Interfaces" onAction="Project1.EMAIL_SOLV_Tickets.SOLV_CommercialInterfaces" visible="true" />
    ......
</mso:dropDown >

The onAction attribute of the buttons has no issue launching macros.

Sub SOLV_Commercial()
        SOLV_emailGenerator ("SAP DS.sap-ds-commercial")
End Sub

The onAction attibute of the dropdown itself does not seem to send anything to the sub.

Sub DDOnAction(control As IRibbonControl, ID As String, index As Integer)
    MsgBox index
End Sub

I have been able to reproduce the behavior I want in an excel file, outlook seems to be a different animal entirely.

.....on Eugenes advice I have added the code below to outlook's project1 and the attribute getSelecteItemIndex to the dropdown above

Sub DDSelctItemIndx(control As IRibbonControl, ByRef index)

    MsgBox index

End Sub

Sub test()

    DDSelctItemIndx ????,???

End Sub

Where I am stuck is what to pass for control and index to sub test to see if this works.

Lindy
  • 1
  • 2
  • Are you saying DDOnAction is not called at all? Why do you declare `Global index As Object`, which conflicts with the parameter name? – Dmitry Streblechenko May 02 '23 at 19:25
  • DDOnAction is not called at all (as far as I can tell). This is the same for any sub that requires the "control" variable to be passed. I tried naming index as a global variable as I had read a post recommending the creation of a global variable to make the process work. I have removed "Global index as object" and there is no change in behavior. – Lindy May 02 '23 at 21:00
  • Is it called only for items, not buttons, right? – Eugene Astafiev May 02 '23 at 21:02
  • the buttons have an onAction assigned works fine, triggering the macros I need. It is the onAction of the dropdown itself that does not seem to work. When I assign an onAction to the item the target macro does not trigger, I expected this though as a selection item does not have this attribute. – Lindy May 02 '23 at 21:10
  • Why do you think that both dropdown and button should call the `onAction` callbacks at the same time? – Eugene Astafiev May 02 '23 at 21:28
  • I don't know of a reason why they shouldn't. in MS open specs both elements have onAction as an attribute. That one is a child of the other should not negate this. – Lindy May 03 '23 at 07:15
  • Indeed they both have, but the dropdown control may contain items that don't have such attributes. For such cases the dropdown control provides the `onAction` callback. For buttons, you need to use the `onAction` callback of the button element, not dropdown. – Eugene Astafiev May 03 '23 at 07:49

1 Answers1

0

Consider using ribbon callbacks for tracking the currently selected index/item for the dropdown control:

  • getSelectedItemID - Asks for the item that should be selected by ID.
  • getSelectedItemIndex - Asks for the item that should be selected by index.

If you need to handle button clicks you need to declare the onAction attribute for the button control. It has the following signature:

C#: void OnAction(IRibbonControl control)

VBA: Sub OnAction(control As IRibbonControl)

C++: HRESULT OnAction([in] IRibbonControl *pControl)

Visual Basic: Sub OnAction(control As IRibbonControl)

Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi Eugene (and thanks), I've added getSelectedItemIndex="Project1.DDSelctItemIndx" as an attribute for the dropdown, and added two subs to Project1 of Outlook. Sub DDSelctItemIndx(control As IRibbonControl, ByRef index) MsgBox index End Sub Sub test() DDSelctItemIndx ????,??? End Sub Where I am stuck is what to pass for control and index to sub test to see if this works. – Lindy May 03 '23 at 07:38
  • Have you tried to repurpose any button outside of the dropdown control? Does it work correctly? – Eugene Astafiev May 03 '23 at 07:47
  • I have taken a button created through the front end ribbon customization process and replaced the onAction macro with another and it works with no issues (although it did reset my other changes to olkesplorer.officeUI at reboot of outlook) – Lindy May 03 '23 at 07:57
  • So, buttons placed on the ribbon without dropdown can be repurposed without issues, right? – Eugene Astafiev May 03 '23 at 12:17
  • Exactly. Buttons placed on the ribbon, and buttons placed on a dropdown on the ribbon, both work without issues. – Lindy May 03 '23 at 14:02
  • So, you have solved the issue posted? – Eugene Astafiev May 03 '23 at 14:04
  • Unfortunately not. I can use the buttons, but each needs a different onAction macro which is pretty cumbersome as I have a lot of selections in the dropdown. If I can get the index of the items to be sent to the macro then I can use that to drive a case select in a single macro. – Lindy May 03 '23 at 15:02
  • So, repurposing buttons instead of dropdown works correctly as I stated previously. You need to use items instead of buttons to get your code working as you want. – Eugene Astafiev May 03 '23 at 15:09
  • Hi Eugune, that is correct. The buttons work, but I really need to use items to scale the solution. – Lindy May 05 '23 at 11:37
  • There is no workaround. That is how the Fluent UI was designed to work. – Eugene Astafiev May 05 '23 at 13:03