msoControlButton to "Worksheet Menu Bar" ?

S

Soniya

Hi All,

I find it easy to add an msoControlPopup menu item to "Worksheet Menu
Bar"

Is it possible to add msoControlButton to "Worksheet Menu Bar" ?

when I tried to get it does,nt work !?

Thanks
 
R

Ron de Bruin

Hi Soniya

Do you want this

Sub MenuBar_Item()
MenuBar_Item_Delete
With Application.CommandBars(1)
With .Controls.Add(Type:=msoControlButton, before:=1)
.Style = msoButtonCaption
.Caption = "&Hi"
.OnAction = ThisWorkbook.Name & "!TestMacro"
End With
End With
End Sub

Sub MenuBar_Item_Delete()
On Error Resume Next
Application.CommandBars(1).Controls("Hi").Delete
On Error GoTo 0
End Sub
 
B

Bob Phillips

Soniya,

This worked for me

With Application.CommandBars("Worksheet Menu Bar")
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test"
.Style = msoButtonCaption
.OnAction = "myMacro"
End With
End With


Note setting the style, this is critical if you want to see the text <G>

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 

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