PDA

View Full Version : toolbar do not show



lior03
12-29-2005, 02:19 AM
hell
i built a custom toolbar .i have assinged a macro to each contol.
why don't i see all the controls & faceid's.i named it johnske in honor of John Skewes a great teacher who taught me a lot.
thanks

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

Marcster
12-29-2005, 03:32 AM
I've copied the code and ran it.
Yep, creates a toolbar named johnske.
It shows 8 buttons on the toolbar.
What happens on your system?.

I've noticed you missed the Sub name on first line.
Also if you've already created the toolbar before
and it's not showing, you need to delete the toolbar
before running the code or you get:
'Invalid procedure call or argument'
error message.


Sub johnskeToolbar()
Dim newbtn As CommandBarButton
On Error Resume Next
'Delete toolbar if exists
Application.CommandBars("johnske").Delete
With Application.CommandBars
.Add("johnske").Visible = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 325
.OnAction = "findafile"
.Caption = "open a file"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 333
.OnAction = "sortworksheets"
.Caption = "sort ws"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 353
.OnAction = "lookfor_demo2"
.Caption = "partial text"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 383
.OnAction = "nnnn"
.Caption = "update comments"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 384
.OnAction = "rowme3"
.Caption = "shade altenate rows"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 395
.OnAction = "horin"
.Caption = "accounting format"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 386
.OnAction = "finders44"
.Caption = "find text"
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 387
.OnAction = "closeallbut"
.Caption = "closeallbut"
End With
End With
End With
End With
End With
End With
End With
End With
End With
End Sub



What happens when you run the code?.
Any error messages?.

Marcster.

Marcster
12-29-2005, 03:40 AM
Here's an add-in which lets you see all the
face-id's and numbers you can use in Excel:

http://j-walk.com/ss/excel/tips/tip67.htm

Marcster.

Bob Phillips
12-29-2005, 03:53 AM
Works fine for me.

BTW, you don't need the multiple layered indenting, it does actually make it harder to read


Dim newbtn As CommandBarButton
With Application.CommandBars
.Add("johnske").Visible = True
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 325
.OnAction = "findafile"
.Caption = "open a file"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 333
.OnAction = "sortworksheets"
.Caption = "sort ws"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 353
.OnAction = "lookfor_demo2"
.Caption = "partial text"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 383
.OnAction = "nnnn"
.Caption = "update comments"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 384
.OnAction = "rowme3"
.Caption = "shade altenate rows"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 395
.OnAction = "horin"
.Caption = "accounting format"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 386
.OnAction = "finders44"
.Caption = "find text"
End With
Set newbtn = CommandBars("johnske").Controls.Add(Type:=msoControlButton)
With newbtn
.FaceId = 387
.OnAction = "closeallbut"
.Caption = "closeallbut"
End With
End With

Bob Phillips
12-29-2005, 03:56 AM
You can simplify it more with no Set


Dim newbtn As CommandBarButton
With Application.CommandBars
.Add("johnske").Visible = True
With CommandBars("johnske")
With .Controls.Add(Type:=msoControlButton)
.FaceId = 325
.OnAction = "findafile"
.Caption = "open a file"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 333
.OnAction = "sortworksheets"
.Caption = "sort ws"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 353
.OnAction = "lookfor_demo2"
.Caption = "partial text"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 383
.OnAction = "nnnn"
.Caption = "update comments"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 384
.OnAction = "rowme3"
.Caption = "shade altenate rows"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 395
.OnAction = "horin"
.Caption = "accounting format"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 386
.OnAction = "finders44"
.Caption = "find text"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 387
.OnAction = "closeallbut"
.Caption = "closeallbut"
End With
End With
End With

johnske
12-31-2005, 02:59 PM
hell
i built a custom toolbar .i have assinged a macro to each contol.
why don't i see all the controls & faceid's.i named it johnske in honor of John Skewes a great teacher who taught me a lot.
thanks...Thanx moshe, that's very flattering. :)

As Bob said in his last post, it's better without all the "Sets", and as he said previous to that, keep all the "Withs" and "End Withs" together so you can keep track of what "With" belongs with each "End With".

Happy New Year,
John :)