How to attach function to a custom Menubar?

  • Thread starter Thread starter Malcom Jazz
  • Start date Start date
M

Malcom Jazz

Thanks for your reply.
I have gone thru your site but I could not found the *function attached
to the command bar*. What is listed is the different macros attached to
the command bar.

Any other solution with functions? Pl do let me know.
Eagerly waiting for functions attached to command bars.

Regards,
Malcom.
 
macros / functions - they are almost the same thing, unless you're referring
to Excel formula functions? I'm not really sure what you're after now.

Normally, to get code to run from a commandbarbutton you set the .OnAction
property to the name of the macro.
You can optionally set the Parameter property to something so you can reuse
procedures. The Tag property can also be used for this property.


Here is a modification to the code on my website for demo:

Sub Toolbar_ON()
Dim bar As CommandBar

Toolbar_OFF

Set bar = Application.CommandBars.Add(Name:=cCommandBar,
Position:=msoBarTop, Temporary:=True)

''' Button 1
With bar.Controls.Add(Type:=msoControlButton)
.FaceId = 136
.Caption = "Click Me1"
.TooltipText = "Click here for a Message Box"
.Style = msoButtonIconAndCaption
.OnAction = "Button_Click"
.Parameter = "1"
End With

''' Button 2
With bar.Controls.Add(Type:=msoControlButton)
.FaceId = 136
.Caption = "Click Me 2"
.TooltipText = "Click here for a Message Box"
.Style = msoButtonIconAndCaption
.OnAction = "Button_Click"
.Parameter = "2"
End With

bar.Visible = True
End Sub

Sub Button_Click()
MsgBox "Button Parameter = " &
Application.CommandBars.ActionControl.Parameter
End Sub
 

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

Back
Top