Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Bar, Whats Wrong? 1

Status
Not open for further replies.

OzzieTheOwl

Technical User
Jun 26, 2006
61
GB
Hi

I have the following code that should be putting a command button into a command bar.

Code:
Private Sub Workbook_Open()
Set cbrGraphs = Application.CommandBars.Add
cbrGraphs.Name = "Graph Buttons"
cbrGraphs.Position = msoBarTop
With cbrGraphsControls
    Set cbcCreateGraphs = .Add(msoControlButton)
    cbcCreateGraphs.Caption = "|Create Graphs|"
    cbcCreateGraphs.DescriptionText = "Click to Create Graphs"
    cbcCreateGraphs.Style = msoButtonCaption
    cbcCreateGraphs.BeginGroup = True
    cbcCreateGraphs.OnAction = "cmdCreateGrphs"
End With
cbrGraphs.Visible = True
End Sub

But I am getting the following error message
Run Time Error 5, Invalid Call or Procedure

On the line
Code:
cbrGraphs.Name = "Graph Buttons"

Am I missing something?

Cheers

Barney
 
What about replacing this:
Set cbrGraphs = Application.CommandBars.Add
cbrGraphs.Name = "Graph Buttons"
cbrGraphs.Position = msoBarTop
with this ?
Set cbrGraphs = Application.CommandBars.Add(Name:="Graph Buttons", Position:=msoBarTop)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV

Much tidier solution.

Have a star

Cheers

Barney
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top