Right click menu vba

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is there a code to add a title to right click menu and/or submenu without the use of xml?
 
Re: Help with Right click menu vba

This is a snippet of my code.
Code:
Sub InsertHeadersClick()

    Dim ContextMenu As CommandBar
    Dim MySubMenu As CommandBarControl
    Call KillInsertHeaderClick
    Set ContextMenu = Application.CommandBars("Cell")
    Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, Before:=1, Temporary:=True) '<----- This is where I am trying to add a faceID/ImageMso

        With MySubMenu
             .Caption = "Headers"
             .Tag = "My_Cell_Control_Tag"
             
        With .Controls.Add(Type:=msoControlButton)
             .OnAction = "Angle"
             .Caption = "Angle"
             .FaceId = 80
        End With
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Re: Help with Right click menu vba

.
Your original posting asked for a "title" to be added to the right click menu. If you are wanting "to add a faceID/ImageMso" look at the following :

Code:
Option Explicit




Sub AddToCellMenu()
    Dim ContextMenu As CommandBar
    Dim MySubMenu As CommandBarControl

    ' Set ContextMenu to the Cell context menu.
    Set ContextMenu = Application.CommandBars("Cell")


    ' Add one built-in button(Save = 3) to the Cell context menu.
    ContextMenu.Controls.Add Type:=msoControlButton, ID:=3, Before:=1
    ContextMenu.Controls.Add Type:=msoControlButton, ID:=370, Before:=1
    
    ' Add one custom button to the Cell context menu.
    With ContextMenu.Controls.Add(Type:=msoControlButton, Before:=1)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "ToggleCaseMacro"
        .FaceId = 59
        .Caption = "Toggle Case Upper/Lower/Proper"
        .Tag = "My_Cell_Control_Tag"
    End With
End Sub


Sub ClearMenu()
    On Error Resume Next
        With Application
            .CommandBars("Cell").Controls("Paste Values").Delete
            .CommandBars("Cell").Controls("Save").Delete
            .CommandBars("Cell").Controls("Toggle Case Upper/Lower/Proper").Delete
        End With
    On Error GoTo 0
End Sub

Resource: https://stackoverflow.com/questions...s-value-icon-to-right-click-menu-cell-context

Workbook download : https://www.amazon.com/clouddrive/share/WFssx77afvzgOCjldlPoNGQ7zdKPhOOq3dvXsRP4RpS
 
Last edited:
Upvote 0
Re: Help with Right click menu vba

Ah my Apologies, I should of taken that out before posting as this was a note to my self so I can add an ID to the right click menu. I am still trying to add a title bar in VBA like a menu separator with a title in xml.

xml Example
Code:
menuSeparator id="MyMenu" title="Add My Data"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,124
Members
449,097
Latest member
mlckr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top