View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default right click menu

Frank's ADd_Item doesn't work for me, if called repeatedly without calling
the Delete_Item in between, it doesn't delete that previously created entry.
I changed it to this to make it work

Sub Add_Item()
Dim New_Entry As Object
Set New_Entry = CommandBars("Cell")
On Error Resume Next
New_Entry.Controls("My message").Delete
On Error GoTo 0
Set New_Entry = New_Entry.Controls.Add(Temporary:=True)

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

Call this code form Worknook_Open event and it will available immediately.

An alternative delete routine

Sub Delete_Item()
Dim myControl As CommandBarButton
On Error Resume Next
CommandBars("Cell").Controls("My message").Delete
On Error Goto 0
End Sub

and to save code you could call this from the add routine rather than
re-code it.

--

HTH

RP

"Frank Kabel" wrote in message
...
Hi
as starting point some code:
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


Sub Message()
MsgBox "Now you code yould start"
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

"PT SPORT CONTRUCTION CO.,LTD" schrieb im
Newsbeitrag ...
how to make it ?