Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
In-place CommandBar.Add run-time error | Excel Discussion (Misc queries) | |||
commandbar problems | Excel Discussion (Misc queries) | |||
Disabling Toolbar buttons and CommandBar items | Excel Programming | |||
Commandbar button running macro | Excel Programming | |||
Controlling Font Name in a personnal Commandbar | Excel Programming |