+ Reply to Thread
Results 1 to 3 of 3

Replace Right-Click menu

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Replace Right-Click menu

    Howdy:

    I want to be able to give my application menu when the user right-clicks on a specific series of cells. I've already got the code that will limit the right-click options to the cells that I want. How do I then form and execute the menu that I want the user to see - "Archive Data", "Edit Data", "Add Data", for instance, rather than the normal right-click menu?

    Any ideas?

    TIA.

    Bob
    Last edited by bstubbs; 07-29-2009 at 04:03 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Replace Right-Click menu

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim ctl As CommandBarControl
    
        If Not Intersect(Target, Me.Range("H1:H10")) Is Nothing Then
        
            With CommandBars("Cell")
            
                For Each ctl In .Controls
                
                    ctl.Visible = False
                Next ctl
                
                With .Controls.Add(Type:=msoControlButton, temporary:=True)
                
                    .Caption = "Archive Data"
                    .OnAction = "ArchiveData"
                End With
                
                With .Controls.Add(Type:=msoControlButton, temporary:=True)
                
                    .Caption = "Edit Data"
                    .OnAction = "EditData"
                End With
                
                With .Controls.Add(Type:=msoControlButton, temporary:=True)
                
                    .Caption = "Add Data"
                    .OnAction = "AddData"
                End With
            End With
        Else
        
            CommandBars("Cell").Reset
        End If
        
    End Sub
    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

  3. #3
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    Re: Replace Right-Click menu

    Cool.

    Thanks.

    Bob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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