CommandBarButton Click Event
I would appreciate if someone could help with this issue. I have four buttons in the CommandBar "CBAR". In the procedure below I am trying to link the first two buttons - "Calculate" and "Rebalance" to the following events - cmdCalculate and cmdRebalance. However, when I click on any of the four buttons from the CommandBar "CBAR" - each will trigger both events - cmdCalculate and cmdRebalance. Thank you, Ivan.
'Class1:
Option Explicit
Public WithEvents cmdCalculate As Office.CommandBarButton
Public WithEvents cmdRebalance As Office.CommandBarButton
Private Sub cmdCalculate_Click(ByVal cmdCalculate As CommandBarButton, CancelDefault As Boolean)
MsgBox CommandBars("CBAR").Controls(1).Caption
End Sub
Private Sub cmdRebalance_Click(ByVal cmdRebalance As CommandBarButton, CancelDefault As Boolean)
MsgBox CommandBars("CBAR").Controls(2).Caption
End Sub
'Module1:
Option Explicit
Private clsCBClass As New Class1
Sub InitEvents()
Dim cmdCalculate As CommandBarButton
Dim cmdRebalance As CommandBarButton
Set clsCBClass.cmdCalculate = CommandBars("CBAR").Controls(1)
Set clsCBClass.cmdRebalance = CommandBars("CBAR").Controls(2)
End Sub
'ThisWorkbook:
Private Sub Workbook_Open()
InitEvents
End Sub
|