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?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Re: Help with Right click menu vba

Hi Logit, I have already created a right click menu, but this still doesn't answer my question of a title bar which names the menu/submenu.
 
Upvote 0
Re: Help with Right click menu vba

You could add a button to it with no macro assigned to it?
 
Upvote 0
Re: Help with Right click menu vba

Hi jkpieterse, I am unable to do that as it's a context menu.
 
Upvote 0
Re: Help with Right click menu vba

Depends on which context menu it is. The cell right-click menu you can add buttons to and to custom right-click menus as well.
 
Upvote 0
Re: Help with Right click menu vba

It's a Right click menu which opens up to the buttons. I have titles for the menus in my add-in which is in xml code. But I would like to have titles for the right click button menu which is in VBA code.
 
Upvote 0
Re: Help with Right click menu vba

.
Paste this into the ThisWorkbook module :

Code:
Option Explicit


Private Sub Workbook_Open()
MsgBox "You can right-click any worksheet cell" & vbCrLf & _
"to see and / or run your workbook's macros.", 64, "A tip:"
Run "RightClickReset"
Run "MakeMenu"
End Sub


Private Sub Workbook_Activate()
Run "RightClickReset"
Run "MakeMenu"
End Sub


Private Sub Workbook_Deactivate()
Run "RightClickReset"
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Run "RightClickReset"
ThisWorkbook.Save
End Sub

Paste this into a routine module :

Code:
Option Explicit


Private Sub RightClickReset()
On Error Resume Next
CommandBars("Cell").Controls("MY ADD-ON MENU").Delete
Err.Clear
CommandBars("Cell").Reset
End Sub


Private Sub MakeMenu()
Run "RightClickReset"
Dim objCntr As CommandBarControl, objBtn As CommandBarButton
Dim strMacroName$
Set objCntr = _
    Application.CommandBars("Cell").Controls.Add(msoControlPopup, before:=1)
    objCntr.Caption = "MY ADD-ON MENU"
End Sub

NOTE: This will create a false Right Click menu button at the top of the right click menu selections. Change the title as desired.

I did a bunch of searching for adding just a title to the right click menu and have not found anything as yet.
 
Upvote 0
Re: Help with Right click menu vba

@Logit: Not sure why you are using
Code:
Run "SubroutineName"
rather than just
Code:
SubroutineName
For one, you risk situations where the former might call that subroutine if it happens to be present in another workbook that is open in Excel too. Also, it breaks any error handling setup in the calling routines.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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