Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Add control to commandbar

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Add control to commandbar

Hi Tom,

Re 1.
I should have thought of .Index instead of "Position".
I also notice you've corrected my declaration of FontCtrl
as Object to CommandBarControl.

Re 2.
The commandbar width is in pixels.

I think that's it..

Declare Function GetSystemMetrics32 Lib "user32" Alias _
"GetSystemMetrics" (ByVal nIndex As Long) As Long

Sub AAtester6()
Dim CmdBar As CommandBar
Set CmdBar = CommandBars("Formatting")
'before adding control
If GetSystemMetrics32(0) - CmdBar.Width < 23 Then
MsgBox "Too wide"
'do something else
End If
'or after adding control
If CmdBar.Width GetSystemMetrics32(0) Then
MsgBox "Re-customize the Formatting toolbar"
End If
End Sub

This assumes a msoControlButton is always 22 pixels?

Many thanks for both,
Dan
-----Original Message-----
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



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
In-place CommandBar.Add run-time error ARHangel Excel Discussion (Misc queries) 4 October 11th 07 06:17 AM
commandbar problems Richard Cook Excel Discussion (Misc queries) 1 July 8th 05 05:32 PM
Disabling Toolbar buttons and CommandBar items Jim[_20_] Excel Programming 2 August 14th 03 02:33 PM
Commandbar button running macro Kwan Kim Chuen Excel Programming 0 July 27th 03 11:51 AM
Controlling Font Name in a personnal Commandbar Luc Dansereau Excel Programming 0 July 12th 03 07:44 PM


All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"