I have a Dropdown control that is very finicky and I'm not sure what is wrong. I modeled it after Ron deBruin's DD example setup and it works some of the time and others, doesn't respond at all.
Here is the code:
Code: Select all
Option Explicit
Dim ItemCount As Integer
Dim ListItemsRg As Range
Dim MySelectedItem As String
Public Sub ddFactbook_getItemCount(control As IRibbonControl, ByRef returnedVal)
With Sheet1.Range("A2:A5") ''Defines where the list of Factbook options is on Sheet1 of ThisWorkbook.
Set ListItemsRg = Range(.Cells(1), .Offset(.Rows.Count).End(xlUp))
ItemCount = ListItemsRg.Rows.Count
returnedVal = ItemCount
End With
End Sub
''Callback for dropdown getItemLabel.
''Called once for each item in drop down.
''If DDItemCount tells Excel there are 10 items in the drop down
''Excel calls this sub 10 times with an increased "index" argument each time.
''We use "index" to know which item to return to Excel.
''Same as RDB's "DDListItem" procedure in his example; he labelled differently.
Public Sub ddFactbook_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
returnedVal = ListItemsRg.Cells(index + 1).Value ''index is 0-based, our list is 1-based so we add 1.
End Sub
''Because there is no direct way for getting a value of a dropdown we must use this
''Dropdown change handler to store the value somewhere if we want to use the value of it in a different macro.
''Called when a drop down item is selected.
Public Sub ddFactbook(control As IRibbonControl, id As String, index As Integer)
MySelectedItem = ListItemsRg.Cells(index + 1).Value
Select Case MySelectedItem
Case "For 2017 work"
Run "Personal.xlsb!factbook2017"
Case "For 2016 work"
Run "Personal.xlsb!factbook2016"
Case "For 2015 work"
Run "Personal.xlsb!factbook2015"
End Select
End Sub
''Returns index of item to display.
Public Sub ddFactbook_getSelectedItemIndex(control As IRibbonControl, ByRef returnedVal)
returnedVal = 0
MySelectedItem = ListItemsRg.Cells(1).Value
End Sub
This is an image of the Tab showing the list of possible selections: Suggestions?
Thanks in advance,
Delain