Create Popup Menu (Right Click menu) using VBA
Here is a simple snippet that will add a menu item to the popup menu and assign a macro to it
Public Const APP_SHORTNAME = "VBADUD_POPUP"
Sub Add_To_Popup_Menu()
Dim ctlNewMenu As CommandBarControl
Dim ctlNewGroup As CommandBarControl
Dim ctlNewItem As CommandBarControl
On Error GoTo Err_Trap
On Error Resume Next
Application.CommandBars("Cell").Controls(APP_SHORTNAME).Delete
On Error GoTo 0
Set ctlNewMenu = Application.CommandBars("Cell").Controls.Add(Type:=msoControlPopup)
ctlNewMenu.Caption = APP_SHORTNAME
'--- Button - Load Raw Data ------------
Set ctlNewItem = ctlNewMenu.Controls.Add(Type:=msoControlButton)
ctlNewItem.Caption = "Process Data"
ctlNewItem.OnAction = "ProcessData"
Err_Trap:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
The above will create a new Group and add the “Process Data” control to it.
Not working
ReplyDelete