making toolbars with a macro

G

Greg Prost

hello,

I'm quite new to this side of macros, but I need to put
something in to my program, probably in the source code,
to remove all of the standard toolbars, and put a
customised one in their place. the toolbar will have
buttons to run macros, each with relevant button images
next to them.
I don't know whether this is possible but i would greatly
appreciate any help anyone can give me. There will be
about 10 buttons needed.

thanks in advance
 
R

Ron de Bruin

Try this example Greg

See this file also
http://support.microsoft.com/default.aspx?scid=kb;en-us;166755&Product=xlw97
XL97: WE1183: "Customizing Menu Bars, Menus, and Menu Items"



Sub MakeToolBar()
Dim bar As CommandBar
On Error Resume Next
Application.CommandBars("MyToolBar").Delete
On Error GoTo 0

For Each bar In Application.CommandBars
bar.Enabled = False
Next

With Application.CommandBars.Add(Name:="myToolBar", Position:=msoBarTop, MenuBar:=False)
' MenuBar:=True hide the Worksheet menubar

.Protection = msoBarNoCustomize
' Prevent users from accessing the Add or Remove Buttons menu

With .Controls.Add(Type:=msoControlButton)
.Caption = "Click me"
.FaceId = 71
.OnAction = "ToolBarMacro"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Delete the ToolBar"
.FaceId = 72
.OnAction = "DeleteToolBar"
End With

' this will add a default Excel button
.Controls.Add Type:=msoControlButton, ID:=4
.Visible = True
End With
End Sub

Sub ToolBarMacro()
MsgBox "Hi"
End Sub

Sub DeleteToolBar()
Dim bar As CommandBar
On Error Resume Next
Application.CommandBars("MyToolBar").Delete
On Error GoTo 0
For Each bar In Application.CommandBars
bar.Enabled = True
Next
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

Top