【发布时间】:2020-03-14 11:20:25
【问题描述】:
我正在尝试删除 Excel 上下文菜单中的一些自定义命令选项。我已将以下子项分配给上下文菜单按钮之一来完成这项工作,但是,当它要删除此按钮本身时,它不能这样做。我该如何实现这一点,或者是否有解决方法,例如将控件释放给另一个子等?
Sub DeleteFromRightClickMenuOptions(sRightClickMenu As String)
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl
' Set ContextMenu to the Cell context menu.
Set ContextMenu = Application.CommandBars(sRightClickMenu) 'instead of "List Range Popup", "Cell" can be used for regulat cells
' Delete the custom controls with the Tag : My_Tag.
For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Tag" Then
ctrl.Delete
End If
Next ctrl
End Sub
【问题讨论】:
标签: excel vba contextmenu