+ Reply to Thread
Results 1 to 3 of 3

Add menu item to right click

  1. #1
    Dev
    Guest

    Add menu item to right click

    How can I add my own menu item to the right click context menu.

    When user clicks on a cell and right clicks; I want my own menu item to be
    seen - so that I can run a macro, when user clicks that menu and also wants
    to disable that menu for some cells...

    Any help is really appreciated!!

    Thanks in advance!!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    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.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Dev
    Guest

    Re: 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
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1