Macro code to create a toolbar?

  • Thread starter Thread starter Do what I can, but I''m only one man.
  • Start date Start date
D

Do what I can, but I''m only one man.

I know this is possible and easily findable; don't bother googling it as I do
not wish to take that much time from you guys (for such simple question).
Thanks in advance.
 
Try some code similar to the following:


Sub AAA()
Dim CBar As Office.CommandBar
Dim C1 As Office.CommandBarButton
Dim C2 As Office.CommandBarButton
Dim C3 As Office.CommandBarButton

On Error Resume Next
Application.CommandBars("MyName").Delete
On Error GoTo 0

Set CBar = Application.CommandBars.Add( _
Name:="MyName", temporary:=True)
Set C1 = CBar.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With C1
.Caption = "One"
.OnAction = "'" & ThisWorkbook.Name & "!ProcedureOne"
.Style = msoButtonCaption
End With
Set C2 = CBar.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With C2
.Caption = "Two"
.OnAction = "'" & ThisWorkbook.Name & "!ProcedureTwo"
.Style = msoButtonCaption
End With
Set C3 = CBar.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With C3
.Caption = "Three"
.OnAction = "'" & ThisWorkbook.Name & "!ProcedureThree"
.Style = msoButtonCaption
End With
CBar.Visible = True
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
I love your MVP website. Thank you Mr. Pearson.

Chip Pearson said:
Try some code similar to the following:


Sub AAA()
Dim CBar As Office.CommandBar
Dim C1 As Office.CommandBarButton
Dim C2 As Office.CommandBarButton
Dim C3 As Office.CommandBarButton

On Error Resume Next
Application.CommandBars("MyName").Delete
On Error GoTo 0

Set CBar = Application.CommandBars.Add( _
Name:="MyName", temporary:=True)
Set C1 = CBar.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With C1
.Caption = "One"
.OnAction = "'" & ThisWorkbook.Name & "!ProcedureOne"
.Style = msoButtonCaption
End With
Set C2 = CBar.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With C2
.Caption = "Two"
.OnAction = "'" & ThisWorkbook.Name & "!ProcedureTwo"
.Style = msoButtonCaption
End With
Set C3 = CBar.Controls.Add(Type:=msoControlButton, _
temporary:=True)
With C3
.Caption = "Three"
.OnAction = "'" & ThisWorkbook.Name & "!ProcedureThree"
.Style = msoButtonCaption
End With
CBar.Visible = True
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
If you google for yourself you don't take any time from "us guys".


Gord Dibben MS Excel MVP
 

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