I want to update the value of cmbType combobox when I change value of cmbYear.
the config of xml file is
<!--RibbonX Visual Designer 2.33 for Microsoft Excel CustomUI14 . XML Code produced on 2020/05/16-->
<customUI
xmlns="http://schemas.microsoft.com/office/2009/07/customui"
onLoad="loadRibbon">
<ribbon >
<tabs >
<tab id="Tab1" label="DBL CnF" insertAfterMso="TabReview">
<group id="Group1" label="Bill of Entries">
<button id="cmdCheck" label="Check BE Data" size="large" imageMso= "Repeat" onAction= "cmdCheck_Click" />
<button id="cmdPrepare" label="Prepare Bill" size="large" imageMso= "RunDialog" onAction= "cmdPompare_Click" />
<button id="cmdPrint" label="Print Report" size="large" imageMso= "RunDialog" onAction= "cmdPrint_Click" />
</group >
<group id="Group2" label="Combo Boxes">
<comboBox id="cmbYear" label="Year: " getItemCount="cmb_getItemCount" getItemID="cmb_getItemID" getItemLabel="cmb_getItemLabel" getText="cmb_getText" onChange="cmb_onChange"/>
<comboBox id="cmbType" label="Year: " getItemCount="cmb_getItemCount" getItemID="cmb_getItemID" getItemLabel="cmb_getItemLabel" getText="cmb_getText" onChange="cmb_onChange"/>
</group >
</tab >
</tabs >
</ribbon >
</customUI >
My current code is
Public myRibbon As IRibbonUI
Public gobjRibbon As office.IRibbonUI
Public yearList As Object
Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
Dim objRibbon As Object
Call CopyMemory(objRibbon, lRibbonPointer, LenB(lRibbonPointer))
Set GetRibbon = objRibbon
Set objRibbon = Nothing
End Function
Public Sub RefreshRibbon()
If gobjRibbon Is Nothing Then
Set gobjRibbon = GetRibbon(Sheet4.Cells(2, 22))
' Else: Do nothing!
End If
On Error Resume Next
gobjRibbon.Invalidate
On Error GoTo 0
End Sub
'Callback for customUI.onLoad
Sub loadRibbon(ribbon As IRibbonUI)
Set gobjRibbon = ribbon
Sheet4.Cells(2, 22) = ObjPtr(ribbon)
End Sub
'Callback for cmbYear getItemCount (called once when the combobox is invalidated)
Sub cmb_getItemCount(control As IRibbonControl, ByRef returnedVal)
If control.id = "cmbYear" Then
Set yearList = CreateObject("System.Collections.ArrayList")
Dim startYear As Long
Dim currentYear As Long
startYear = 2020
currentYear = Year(Now)
For i = startYear To currentYear
yearList.Add i
Next i
returnedVal = yearList.count
End If
End Sub
'Callback for cmbYear getItemID (called 10 times when combobox is invalidated)
Public Sub cmb_getItemID(control As IRibbonControl, index As Integer, ByRef id)
End Sub
'Callback for cmbYear getItemLabel (called 10 times when combobox is invalidated)
Sub cmb_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
If control.id = "cmbYear" Then
returnedVal = yearList(index)
End If
End Sub
'Callback for cmbYear getText
Sub cmb_getText(control As IRibbonControl, ByRef returnedVal)
If control.id = "cmbYear" Then returnedVal = Year(Now)
End Sub
'Callback for cmbYear onChange
Sub cmb_onChange(control As IRibbonControl, id As String)
If control.id = "cmbYear" Then
Dim comboBox As Object
Set comboBox = Application.CommandBars.FindControl(id:=cmbtype)
'Here I want to run my logic if selected value of cmbYear is less than current year then the value of cmbType will be "OLD"
End If
End Sub
the findcontrol method does return with runtime error 438.
I am new in ribbonUI and cant find any topic related to this is working. the main problem I am facing is I cant get control of another ofject such as combobox from event occurrs in different object. Is there any way to do this?
Nahid Hossain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.