Context sensitive menu

M

Mark

Hi NG

Is there someway to add items to the right mouse menu in Excel?
And perhaps even do it dynamically, so that one get some sort of context
sensitive menu?

Regards
Mark
 
F

Frank Kabel

Hi Mark
try the following procedures (they add/delete an entry to the cell
context menu):


Sub Add_Item()
Dim New_Entry As Object
Set New_Entry = CommandBars("Cell").Controls.Add(Temporary:=True)
With New_Entry
.Caption = "My message"
.OnAction = "Message"
End With
End Sub

Sub Message()
MsgBox "My message is here - put code at this place"
End Sub

Sub Delete_Item()
Dim myControl As CommandBarButton
For Each myControl In CommandBars("Cell").Controls
If myControl.Caption = "My message" Then
myControl.Delete
End If
Next
End Sub
 
B

Bob Phillips

Suggested slight amendment to Frank's code, just as an insurance

Sub Add_Item()
Dim New_Entry As Object
Set New_Entry = CommandBars("Cell").Controls.Add(Temporary:=True)

On Error Resume Next
New_Entry.Controls("My message").Delete
On Error Goto 0

With New_Entry
.Caption = "My message"
.OnAction = "Message"
End With
End Sub

I would also suggest that you look at John Walkenbach's faceid to see what
built-in faceids youy could select from
http://j-walk.com/ss/excel/tips/tip67.htm

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
M

Mark

Thanks alot! works like a charm. :)


Frank Kabel said:
Hi Mark
try the following procedures (they add/delete an entry to the cell
context menu):


Sub Add_Item()
Dim New_Entry As Object
Set New_Entry = CommandBars("Cell").Controls.Add(Temporary:=True)
With New_Entry
.Caption = "My message"
.OnAction = "Message"
End With
End Sub

Sub Message()
MsgBox "My message is here - put code at this place"
End Sub

Sub Delete_Item()
Dim myControl As CommandBarButton
For Each myControl In CommandBars("Cell").Controls
If myControl.Caption = "My message" Then
myControl.Delete
End If
Next
End Sub
 
M

Mark

Error handling is always nice :)
Thanks for the link to the faceid application. This will definitetly come
in handy! :)

/Mark
 

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

Top