VBA: 如何禁用右键单击上下文菜单中的某些选项

VBA: How can I disable some options from right-click context menu

我需要

1) 从 "Cells" 右键单击​​上下文菜单

禁用以下所有选项
a.  Paste options
b.  Insert
c.  Delete
d.  Format Cell

2) 从"Columns"右键单击上下文菜单

禁用以下所有选项
a.  Paste options
b.  Insert
c.  Delete
d.  Clear Content
e.  Format Cell

3) 从 "Rows" 右键单击​​上下文菜单

禁用以下所有选项
a.  Paste options
b.  Insert Copied Cells only (Not Insert)
c.  Format Cell

4) 从 "Rows" 右键单击​​上下文菜单中针对特定行范围(例如第 1 到 3 行)禁用以下所有选项

a.  Insert
b.  Delete
c.  Clear Content

5) 从“表单控制按钮”右键单击上下文菜单禁用以下所有选项

a.  Format Control

感谢任何帮助

这里有一个简单的方法来实现你想要的。对于其中的大多数,您可以完全使用您在右键单击菜单中看到的内容。例如,对于 Insert,您会看到 Insert...

Application.CommandBars("Cell").Controls("Insert...").Visible = True 'False

其他人也一样。我还没有找到禁用 Paste Options: 或其中的图标的方法。但是,您可以使用 Paste Special...

禁用 Paste Options: 下的 Paste Special

注意:好吧,这是你的问题中最少的。请记住,用户仍然可以使用功能区或快捷键来实现您禁用的功能;)

编辑

Unfortunately doesn't work for me. Does it have anything to do with Tables? because cells are part of a table! – Afshin Davoudy 8 mins ago

是的,你必须使用

Application.CommandBars("List Range Popup").Controls("Delete").Visible = False

之前

之后

Afshin Davoudy: how can I disable options in "Column" context menue? or Rows? (From Extended Chat)

使用

Application.CommandBars("Column").Controls("Delete").Visible = False
Application.CommandBars("Row").Controls("Delete").Visible = False