Maybe use this
fill in the caption and macro name in the array
onaction_names = Array("macro1", "macro2", "macro3")
caption_names = Array("caption 1", "caption 2", "caption 3")
Sub Add_Controls()
Dim i As Long
Dim onaction_names As Variant
Dim caption_names As Variant
Delete_Controls
onaction_names = Array("macro1", "macro2", "macro3")
caption_names = Array("caption 1", "caption 2", "caption 3")
With Application.CommandBars("Cell")
For i = LBound(onaction_names) To UBound(onaction_names)
With .Controls.Add(Type:=msoControlButton)
.OnAction = ThisWorkbook.Name & "!" & onaction_names(i)
.Caption = caption_names(i)
End With
Next i
End With
End Sub
Sub Delete_Controls()
Dim i As Long
Dim caption_names As Variant
caption_names = Array("caption 1", "caption 2", "caption 3")
With Application.CommandBars("Cell")
For i = LBound(caption_names) To UBound(caption_names)
On Error Resume Next
.Controls(caption_names(i)).Delete
On Error GoTo 0
Next i
End With
End Sub
--
Regards Ron de Bruin
http://www.rondebruin.nl
"Gord Dibben" <gorddibbATshawDOTca> wrote in message news:
[email protected]...
I just add another set of code within the Workbook_Open Sub.
With Application.CommandBars("Cell").Controls.Add(temporary:=True)
.Caption = "Clear Formats"
.OnAction = "MyMacros.xla" & "!Change References"
End With
I have added two groups of three items each to the bottom of my r-click menu
in this manner.
I have had no success trying to add more than one item within the With/End
With lines, but VBA is not my strong suit.
It's more like my birthday suit, which is kinda wrinkly<g>
There is most likely a way. Others will jump in if you hang around.
I think Ron's code with the Control ID is easier to use for exact placement.
Let's watch this thread so's we both can learn.
Gord