So I found a code on the internet & changed it a bit and I think I'm almost there...
The code uses a custom class which raises an event for a specified command.
In the example below i use an ID 21 which refers to the "Cut" command - i have chosen it for testing because the id 21 is the same both for the context menu and the tab menu as well.
It works perfectly when you right click on a cell and press cut (in the context menu), but for some reason I cannot make it work for the Home Tab button.
Any thoughts on what is the issue here?
--> Paste to ThisWorkbook event window:
Private Sub Workbook_Open()
InitEvents
End Sub
--> Create a Class named Class1 and paste the below:
Public WithEvents cmdCalculate As Office.CommandBarButton
Private Sub cmdCalculate_Click(ByVal cmdCalculate As CommandBarButton, CancelDefault As Boolean)
MsgBox "Hello"
End Sub
--> Create a normal module and paste the below:
Private clsCBClass As New Class1
Sub InitEvents()
Dim cmdCalculate As CommandBarButton
Set clsCBClass.cmdCalculate = Application.CommandBars.FindControl(ID:=21)
End Sub
Bookmarks