Hi all,
I want to trap the click event on a menu item, to run code to be determined at run time. I have created a class with a single member (CommandBarButton) and have (successfully?) instantiated it in the system - they do display as required.
However, the click event is not being trapped. Below is the full code for the class, and code scrap for instances.
Any help appreciated.
Cheers & thanks
Steve
The Class ButtonsClass
Instantiating the object
I want to trap the click event on a menu item, to run code to be determined at run time. I have created a class with a single member (CommandBarButton) and have (successfully?) instantiated it in the system - they do display as required.
However, the click event is not being trapped. Below is the full code for the class, and code scrap for instances.
Any help appreciated.
Cheers & thanks
Steve
The Class ButtonsClass
Code:
Option Explicit
Public WithEvents mButton As Office.CommandBarButton
Private Sub Class_Initialize()
End Sub
Private Sub mButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
Debug.Print "Clicked " & mButton.Caption
End Sub
Private Function IsCPReportCurrent() As Boolean
Dim targetName As String
targetName = "CPReportData.xls"
makeCPCurrent = (Application.ActiveWorkbook.Name = targetName)
End Function
Instantiating the object
Code:
...
Set cbtn = New ButtonsClass
Set cbtn.mButton = cbc.Controls.Add
(Type:=msoControlButton)
With cbtn.mButton
.Caption = shNames(i)
.BeginGroup = False
End With
...