David G
David G

Reputation: 2355

Custom right click while inside a cell

I have a custom right click menu using the following syntax to add stuff to the context menu:

Function RightClickOnMoMAction(targ As String)
    Dim cbar As CommandBar
    Set cbar = Application.CommandBars("Cell")

    With cbar.Controls.add(Temporary:=True, Type:=msoControlButton, before:=1)
        .BeginGroup = False
        .FaceId = 1111
        .Caption = targ
        .OnAction = "'" & ThisWorkbook.Name & "'!'rcFollowSlide """ & targ & """" & "'"
    End With
End Function

It works very well when I right click a cell. However, when I "enter" in the cell, for example if I'm writing something inside the cell, the right click has a different context menu altogether. How do I trap the right click when INSIDE a cell? If it's even possible. I want to have access to my custom menu in both cases.

For reference, here is my context menu:

enter image description here

And here is the right click when editing the inside of a cell (The cursor disappeared but I drew it in blue over the screen capture, I am writing in the cell):

enter image description here

Upvotes: 0

Views: 346

Answers (1)

basodre
basodre

Reputation: 5780

That is accessed through the Formula Bar Commandbar.

See the following code and let us know if it resolves the problem.

Dim cbar As CommandBar

Set cbar = Application.CommandBars("Formula Bar")

With cbar.Controls.Add(Temporary:=True, Type:=msoControlButton, Before:=1)
    .FaceId = 1111
    .Caption = "TEST"
End With

Upvotes: 1

Related Questions