Removing right-click menu items

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm making a workbook to be used by many other people, and so the workbook is protected and most of the sheets are protected. Because of this, I want to eliminate several items from the cell right-click menu, since they will always be greyed out. I was able to get most of the items removed, with two exceptions. See below.

right click menu.jpg


Here is the code I used to remove the items.

VBA Code:
Sub RCM_HideItems()

Dim RCM As CommandBar

' Access the Cell context menu (right-click menu)
Set RCM = Application.CommandBars("Cell")

On Error Resume Next

' Hide the "Cut" option
RCM.FindControl(ID:=21).Visible = False

' Hide the "Insert Cells" (called "Cells" on Mac) option
RCM.FindControl(ID:=295).Visible = False

' Hide the "Delete" option
RCM.FindControl(ID:=292).Visible = False

' Hide the "Clear Contents" option
RCM.FindControl(ID:=3125).Visible = False

' Hide the "Filter" option
RCM.FindControl(ID:=31402).Visible = False

' Hide the "Sort" option
RCM.FindControl(ID:=31435).Visible = False

' Hide the "Pick From Drop-down List" option
RCM.FindControl(ID:=1966).Visible = False

' Hide the "Define Name" option
RCM.FindControl(ID:=13380).Visible = False

' Hide the "Link to this Range" option
RCM.FindControl(ID:=34646).Visible = False

' Hide the "Open Hyperlink" option
RCM.FindControl(ID:=1015).Visible = False

'These items are only for Windows.
If Not IsMac Then

    ' Hide the "Quick Analysis" option
    RCM.FindControl(ID:=24508).Visible = False
   
    ' Hide the "Get Data from Table/Range" option
    RCM.FindControl(ID:=34003).Visible = False

End If

On Error GoTo 0

Set RCM = Nothing

End Sub

You will notice I have code to remove "Insert Cells". But perhaps just "Insert" is a different ID?

I also have one in that should hide "Link to this Range", but perhaps "Link" is also a different ID?

I used some other code to generate a list of all of the right-click options, along with their ID's, on both Windows and Mac. (My workbook needs to work on both.) I created this just the other day, so I believe all of the ID's are current.

Control ID
Control Name​
WindowsMac
Cu&t​
21​
21​
&Copy​
19​
19​
&Paste​
22​
22​
Paste &Special...​
21437​
755​
&Paste Table​
3624​
Smart &Lookup​
25536​
25536​
&Show Data Type Card​
32714​
32714​
Data T&ype​
32713​
32713​
&Picture in Cell​
34738​
34738​
View &Alt Text...​
34737​
34737​
&Copilot​
34820​
34820​
Insert C&ells...​
295​
295​
&Delete...​
292​
292​
Clear Co&ntents​
3125​
3125​
Translate​
33409​
33409​
P&ython Output​
34750​
34750​
Display &Plot over Cells​
45242​
35077​
Show &Diagnostics​
34713​
34713​
&Quick Analysis​
24508​
Sp&arklines​
31623​
31623​
Filt&er​
31402​
31402​
S&ort​
31435​
31435​
&Get Data from Table/Range...​
34003​
Insert Co&mment​
2031​
2031​
Delete Co&mment​
1592​
1592​
Sh&ow/Hide Comments​
1593​
1593​
&Format Cells...​
855​
855​
Pic&k From Drop-down List...​
1966​
1966​
&Show Phonetic Field​
1614​
1614​
Define N&ame...​
13380​
13380​
&Open with​
34600​
34600​
Set o&pen default​
34680​
34680​
Set O&pen Default​
49649​
35174​
&Hyperlink...​
1576​
1576​
Edit &Hyperlink...​
1577​
1577​
&Open Hyperlink​
1015​
1015​
&Remove Hyperlink​
3626​
3626​
&Link to this Range​
34646​
34646​
Show Chan&ges​
34405​
34405​
E&xpand to detail​
11299​
11299​
Additional Act&ions​
31595​
31595​
F&ull Screen​
178​
178​
Hide Ot&hers​
34125​
34125​
&Additional Actions​
22577​
People &Near Me​
34042​
34042​
&Thesaurus...​
9056​
New Co&mment​
33164​
&New Note​
33158​

(I don't know why one of the columns above is so much wider than the others. I don't know how to change it.)

There is no listing for "Insert" or "Link", so I am not sure how I am supposed to know what the ID number is for those. So, I'm at a loss for how I would hide those two. Any ideas?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Thanks for the link, but from what I can tell, any user who was using my file would need to install this add-in in order for my changes to the right-click menu to be in affect. Does that sound correct to you, or am I misunderstanding how it works?
 
Upvote 0
If you are creating a workbook for others to utilize and you install the add-in ... the user will see that the right click menu items have been disabled.

Did I misunderstand your overall project ?
 
Upvote 0
Oh, okay... sorry, I thought the user would also need to install the add-in themselves. In that case, I will check it out and see if it helps solve my problem.
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

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