LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
dev dev is offline
external usenet poster
 
Posts: 66
Default Add menu item to right click

Thanks Leith for your reply. This worked!!

"Leith Ross" wrote:


Hello Dev,

Copy this code and paste it into a new VBA Module in your Workbook. Run
it once to add your menu item to the Right-Click menu. Besure to change
MyMacro and MyMenuCaption to what you want.


Code:
--------------------

Public Sub AddToContextMenu()

Dim C
Dim cmdNew As CommandBarButton
Dim MyMenuCaption As String

MyMenuCaption = "Call MyMacro" '<<<< Change this

'Don't add the Menu if it exists.
For Each C In Excel.CommandBars("cell").Controls
If C.Caption = MyMenuCaption Then
Exit Sub
End If
Next C

Set cmdNew = Excel.CommandBars("cell").Controls.Add
With cmdNew
.Caption = MyMenuCaption
.OnAction = "MyMacro name" '<<< Insert the name of your Macro
.BeginGroup = True
End With

End Sub

Public Sub RemoveFromContextMenu()

Dim MyMenuCaption As String

On Error Resume Next
MyMenuCaption = "Call MyMacro" '<<<< Change this
With CommandBars("cell").Controls(MyMenuCaption)
.BeginGroup = False
.Delete
End With

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=561910


 
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
Add menu item to right-click menu [email protected] Excel Programming 1 July 15th 06 10:32 AM
Adding a item to the right click menu? silkworm Excel Programming 3 December 24th 05 05:28 AM
How to delete item on right click menu? Bobo Excel Discussion (Misc queries) 1 August 28th 05 04:53 PM
Add item to sheet right-click menu? RB Smissaert Excel Programming 5 May 13th 05 04:13 PM
Adding a menu item right click menu when clicking on a single. Andoni[_28_] Excel Programming 0 September 2nd 04 10:23 PM


All times are GMT +1. The time now is 03:29 AM.

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"