ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Context sensitive menu (https://www.excelbanter.com/excel-programming/293264-context-sensitive-menu.html)

Mark[_36_]

Context sensitive menu
 
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



Frank Kabel

Context sensitive menu
 
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


--
Regards
Frank Kabel
Frankfurt, Germany

Mark wrote:
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



Bob Phillips[_6_]

Context sensitive menu
 
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)

"Frank Kabel" wrote in message
...
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


--
Regards
Frank Kabel
Frankfurt, Germany

Mark wrote:
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





Frank Kabel

Context sensitive menu
 
Hi Bob
good point!

--
Regards
Frank Kabel
Frankfurt, Germany
"Bob Phillips" schrieb im
Newsbeitrag ...
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)

"Frank Kabel" wrote in message
...
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


--
Regards
Frank Kabel
Frankfurt, Germany

Mark wrote:
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






Mark[_36_]

Context sensitive menu
 
Thanks alot! works like a charm. :-)


"Frank Kabel" wrote in message
...
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


--
Regards
Frank Kabel
Frankfurt, Germany

Mark wrote:
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





Mark[_36_]

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

/Mark

"Bob Phillips" wrote in message
...
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)

"Frank Kabel" wrote in message
...
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


--
Regards
Frank Kabel
Frankfurt, Germany

Mark wrote:
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








All times are GMT +1. The time now is 09:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com