Adding a item to the right click menu?

  • Thread starter Thread starter silkworm
  • Start date Start date
Hello Silkworm,

Yes it is. Which of the right click menus did you have in mind?

Sincerely,
Leith Ros
 
Thanks for replying. I should've been more clear. What I have in mind
is to write some VBA code, and when a user right click on a cell, have
the right-click menu display the option to run the script.
 
Hello Silkworm,

The following macros Add or Remove your custom control from the contex
menu (right click) for Worksheet cells. Once you add your control, i
will remain on the menu until you run the remove macro. You run thi
when you close your program. Otherwise the macro will not be availabl
to other Workbooks eventhough the control still appears on the menu
Change the Caption property to what your control does, and the OnActio
property to the name of the macro to run.
_____________________________


Code
-------------------
Public Sub AddToContextMenu()

Dim C
Dim cmdNew As CommandBarButton

'Don't add the Menu if it exists.
For Each C In Excel.CommandBars("cell").Controls
If C.Caption = "Change Cell and Font Colors" Then
Exit Sub
End If
Next C

Set cmdNew = Excel.CommandBars("cell").Controls.Add
With cmdNew
.Caption = "Change Cell and Font Colors"
.OnAction = "ChangeCellColor"
.BeginGroup = True
End With

End Sub

Public Sub RemoveFromContextMenu()

On Error Resume Next
With CommandBars("cell").Controls("Change Cell and Font Colors")
.BeginGroup = False
.Delete
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top