How to respond the click event of submenu
I am writing a addin for RobotStudio, and I add a submenu under "Tools". But I cannot respond the click event of it.
I tried to define a menu and a submenu as :
Public MyMenu As CommandBarPopup
Public WithEvents MySubMenu As CommandBarButton
But it returns an error message:"Object or class does not support the set of events"
Could you give me a hand?
Comments
-
Here is some simple code to start with
Dim WithEvents mRSE As RSE
Dim mToolsMenu As CommandBarPopup
Dim mMyMenu As CommandBarControl
Dim lngMyID As LongSub CreateMenu()
On Error Resume Next
Set mRSE = Application.RSE
Set mToolsMenu = mRSE.CommandBars("Menu Bar").Controls("Tools")
Set mMyMenu = mToolsMenu.Controls.Add(rsControlButton, "My Menu")
lngMyID = mMyMenu.IdEnd Sub
Private Sub mRSE_CommandBarControlClick(ByVal CommandID As Long, CancelDefault As Boolean)
If lngMyID = CommandID Then
MsgBox "You have clicked on my menu..."
End If
End SubPer Svensson
Company Specialist
ABB Automation Technology Products0 -
If you wish to make your code a bit more readable then I wouldn't save the ID but instead check it like this:
Dim WithEvents mRSE As RSE
Dim mToolsMenu As CommandBarPopup
Dim mMyMenu As CommandBarControlSub CreateMenu()
On Error Resume Next
Set mRSE = Application.RSE
Set mToolsMenu = mRSE.CommandBars("Menu Bar").Controls("Tools")
Set mMyMenu = mToolsMenu.Controls.Add(rsControlButton, "My Menu")End Sub
Private Sub mRSE_CommandBarControlClick(ByVal CommandID As Long, CancelDefault As Boolean)
If CommandID = Application.RSE.CommandBars("Menu Bar").Controls("Tools").Controls("My Menu").Id Then
MsgBox "You have clicked on my menu..."
End If
End SubJohn
Developer Center0 -
But to make it language independent, I think using ID is better
/Martin Lundh
Product manager
ABB Robotics0 -
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 314 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 794 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings