I am trying to delete some custom command options in the context menu of Excel. I have assigned the following sub to one of the context menu buttons to do the job, however, when it gets to delete this button itself, it cannot do that. How can I achieve this, or is there a workaround such as releasing the control to another sub, etc?
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