Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is it possible to add customized menu to the mouse right click pop-up menu
and attach script to be executed with it? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This example adds a Custom command to the Cell shortcut menu when the
workbook the code is in opens. It then removes it when closed: FIRST, copy and paste (and modify as desired) the routines listed below in the ThisWorkbook object (in the VBE) of the desired workbook: __________________________________________ Const mszTAG As String = "C&ustom Command" 'Is the name that appears on the shortcut menu Private Sub Workbook_Open() Dim cbr As CommandBar Dim ctl As CommandBarControl Set cbr = Application.CommandBars("Cell") 'Add your custom command to the cells shortcut menu With cbr Set ctl = .Controls.Add(msoControlButton) 'By default, the control appears at the bottom of the menu With ctl .BeginGroup = True 'This adds a separator before the custom control .Caption = mszTAG 'This is what appears on the Right-Click (shortcut) menu .Tag = mszTAG 'Assigning mszTAG to this property allows us to search for and delete the command when the workbook closes .OnAction = "CustomCommand" 'Is the name of the macro that runs when you click the custom command End With End With End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) 'Remove it On Error Resume Next 'Find and delete the control on the Right-Click menu (called the Cell commandbar) based on ' the text found in the control's .Tag property, which is mszTAG. Application.CommandBars("Cell").FindControl(, , mszTAG).Delete End Sub __________________________________________ SECOND, in a regular module, place the following routine, which is the macro the custom command will run when it's clicked: Sub CustomCommand() 'Access the control clicked (called the ActionControl) and display it's Caption in a message box MsgBox CommandBars.ActionControl.Caption End Sub -- _______________________ Robert Rosenberg R-COR Consulting Services Microsoft MVP - Excel "Jack" <replyto@newsgroup wrote in message ... Is it possible to add customized menu to the mouse right click pop-up menu and attach script to be executed with it? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Right click mouse menu for insert does not work | Excel Discussion (Misc queries) | |||
Shortcut menu won't appear when I click right mouse button. | Excel Discussion (Misc queries) | |||
adding macro to right mouse click menu | Excel Discussion (Misc queries) | |||
pls help: short cut menu doesn't show when right click mouse | Excel Programming | |||
short cut menu doesn't show when right click on mouse | Excel Programming |