Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Adding menu to the mouse right click pop-up menu

Is it possible to add customized menu to the mouse right click pop-up menu
and attach script to be executed with it?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Adding menu to the mouse right click pop-up menu

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Right click mouse menu for insert does not work SueK Excel Discussion (Misc queries) 2 November 3rd 09 08:02 PM
Shortcut menu won't appear when I click right mouse button. jngrant28 Excel Discussion (Misc queries) 3 June 17th 08 05:23 PM
adding macro to right mouse click menu JimB Excel Discussion (Misc queries) 1 October 31st 05 03:37 PM
pls help: short cut menu doesn't show when right click mouse Yong Wah Excel Programming 1 October 23rd 03 01:56 PM
short cut menu doesn't show when right click on mouse Yong Wah Excel Programming 2 October 21st 03 01:42 PM


All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"