Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Delete context menu options invoked from inside the context menu itself

$
0
0

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

Viewing all articles
Browse latest Browse all 88868

Trending Articles