PDA

View Full Version : toolbar mishap



lior03
02-02-2006, 01:39 AM
hello all
i have vba code for a toolbar . i place it's name in workbook open event.
i keep getting an error message.
why?
the code:

Sub cmd()
Dim newbtn As CommandBarButton
Application.CommandBars.Add ("johnske")
With CommandBars("johnske")
.Position = msoBarTop
.Visible = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 375
.OnAction = "vin1"
.Caption = "filter data"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 325
.OnAction = "findafile"
.Caption = "open a file"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 469
.OnAction = "sortworksheets"
.Caption = "sort ws"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 353
.OnAction = "lookfor_demo2"
.Caption = "partial text"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 383
.OnAction = "nnnn"
.Caption = "update comments"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 384
.OnAction = "rowme3"
.Caption = "shade altenate rows"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 395
.OnAction = "horin"
.Caption = "accounting format"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 386
.OnAction = "finders44"
.Caption = "find text"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 387
.OnAction = "closeallbut"
.Caption = "closeallbut"
.BeginGroup = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 396
.OnAction = "daphnebook"
.Caption = "vbaexpress"
.BeginGroup = True
End With
End With
End With
End With
End With
End With
End With
End With
End With
End With
End With
End Sub


thanks

Bob Phillips
02-02-2006, 02:25 AM
Haven't we been here before?


Sub cmd()
Dim oCB As CommandBar
Dim newbtn As CommandBarButton
Set oCB = Application.CommandBars.Add(Name:="johnske", temporary:=True)
With oCB
.Position = msoBarTop
.Visible = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 375
.OnAction = "vin1"
.Caption = "filter data"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 325
.OnAction = "findafile"
.Caption = "open a file"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 469
.OnAction = "sortworksheets"
.Caption = "sort ws"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 353
.OnAction = "lookfor_demo2"
.Caption = "partial text"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 383
.OnAction = "nnnn"
.Caption = "update comments"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 384
.OnAction = "rowme3"
.Caption = "shade altenate rows"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 395
.OnAction = "horin"
.Caption = "accounting format"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 386
.OnAction = "finders44"
.Caption = "find text"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 387
.OnAction = "closeallbut"
.Caption = "closeallbut"
.BeginGroup = True
End With
Set newbtn = oCB.Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 396
.OnAction = "daphnebook"
.Caption = "vbaexpress"
.BeginGroup = True
End With

End Sub

Killian
02-02-2006, 02:34 AM
What is the error and where does it occur?

Runs OK for me (WinXP/XL2003)

I think you might want to close your with block for each newbtn though... as posted above

Bob Phillips
02-02-2006, 02:58 AM
What is the error and where does it occur?

Runs OK for me (WinXP/XL2003)

I think you might want to close your with block for each newbtn though... as posted above

The Commandbars failed on XP for me, I had to add Application.