View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Add control to commandbar

Sub AAtester5()
Dim FontCtrl As CommandBarControl
Dim nwCtrl As CommandBarControl
With Application.CommandBars("Formatting")
Set FontCtrl = .FindControl(Id:=1691)
If FontCtrl.Index < .Controls.Count Then
Set nwCtrl = .Controls.Add(Type:=msoControlButton, _
Befo=FontCtrl.Index + 1)
Else
Set nwCtrl = .Controls.Add(Type:=msoControlButton)
End If
End With
nwCtrl.Caption = "MyControl"
End Sub

I have never played with your second question - I guess you could sum up the
width of the controls or look at the width of the bar and check it against
the width of the window. The commandbar width is in pixels. If I have
time to play with it I will post back if I come up with anything - hopefully
someone else has some experience with this.

--
Regards,
Tom Ogilvy



Dan wrote in message
...
Hi all

1. I want to add a control before "&Fill Color" on the
Formatting commandbar. I'm stuck and frustrated!

In this effort "After:=FontCtrl" is clearly wrong

Sub Test()
Dim FontCtrl As Object
With Application.CommandBars("Formatting")
Set FontCtrl = .FindControl(Id:=1691)
'1691 is Fill Color ID
'MsgBox FontCtrl.Caption
.Controls.Add(Type:=msoControlButton, _
after:=FontCtrl).Caption = "MyCaption" 'fails
'also .OnAction, .Tag etc
End With
End Sub

2. I've noticed some customized toolbars extend to the
right of the screen. What would be the best approach to
ensure I am neither putting my new control, nor pushing
any others off the screen.

TIA,
Dan