J
John Keith
' new CB defined
Dim cbrBar As Office.CommandBar
Set cbrBar = Application.CommandBars.Add("New CB")
With cbrBar
.Visible = True
.Enabled = True
.Position = msoBarTop
End With
'1st control
Dim ctlControl As Office.CommandBarControl
Set ctlControl = cbrBar.Controls.Add(msoControlDropdown)
With ctlControl
.Tag = "OrderType"
.BeginGroup = True
.Caption = "Type:"
.Style = msoComboLabel
.Enabled = True
.TooltipText = "Choose the Order type."
.OnAction = "Toggle_Type"
.DropDownLines = 2
.ListHeaderCount = 0
.AddItem "Food"
.AddItem "Produce"
End With
'2nd Control
Set ctlControl = cbrBar.Controls.Add(msoControlDropdown)
With ctlControl
.Tag = "FromCycle"
.BeginGroup = True
.Caption = "From:"
.Style = msoComboLabel
.Enabled = True
.TooltipText = "Choose the starting cycle."
.OnAction = "Lookup_Cycle"
.DropDownLines = fromCyc.Count
.ListHeaderCount = 0
For Each rngCell In fromCyc.Cells
.AddItem rngCell.Value
Next rngCell
.ListIndex = 1
End With
************************************************
'In a seperate module of the same project...
Dim cbrBar As Office.CommandBar
Dim ctlToggle As Office.CommandBarControl
Dim ctlFromCycle As Office.CommandBarControl
Set cbrBar = Application.CommandBars("NewCB")
Set ctlToggle = cbrBar.Controls(1) 'OrderType
Set ctlFromCycle = cbrBar.Controls(2) 'FromCycle
** now for my question **
How can I "set" the reference to Controls for OrderType and FromCycle with
out having to use the (1)<-hardcoded item number?
Why won't something like:
Set ctlToggle = cbrBar.Controls("OrderType")
Set ctlFromCycle = cbrBar.Controls("FromCycle")
....assign the reference properly. (Or) What is the proper syntax to assign
the reference by the name (have I missed assigning a property that would
allow it?)
Dim cbrBar As Office.CommandBar
Set cbrBar = Application.CommandBars.Add("New CB")
With cbrBar
.Visible = True
.Enabled = True
.Position = msoBarTop
End With
'1st control
Dim ctlControl As Office.CommandBarControl
Set ctlControl = cbrBar.Controls.Add(msoControlDropdown)
With ctlControl
.Tag = "OrderType"
.BeginGroup = True
.Caption = "Type:"
.Style = msoComboLabel
.Enabled = True
.TooltipText = "Choose the Order type."
.OnAction = "Toggle_Type"
.DropDownLines = 2
.ListHeaderCount = 0
.AddItem "Food"
.AddItem "Produce"
End With
'2nd Control
Set ctlControl = cbrBar.Controls.Add(msoControlDropdown)
With ctlControl
.Tag = "FromCycle"
.BeginGroup = True
.Caption = "From:"
.Style = msoComboLabel
.Enabled = True
.TooltipText = "Choose the starting cycle."
.OnAction = "Lookup_Cycle"
.DropDownLines = fromCyc.Count
.ListHeaderCount = 0
For Each rngCell In fromCyc.Cells
.AddItem rngCell.Value
Next rngCell
.ListIndex = 1
End With
************************************************
'In a seperate module of the same project...
Dim cbrBar As Office.CommandBar
Dim ctlToggle As Office.CommandBarControl
Dim ctlFromCycle As Office.CommandBarControl
Set cbrBar = Application.CommandBars("NewCB")
Set ctlToggle = cbrBar.Controls(1) 'OrderType
Set ctlFromCycle = cbrBar.Controls(2) 'FromCycle
** now for my question **
How can I "set" the reference to Controls for OrderType and FromCycle with
out having to use the (1)<-hardcoded item number?
Why won't something like:
Set ctlToggle = cbrBar.Controls("OrderType")
Set ctlFromCycle = cbrBar.Controls("FromCycle")
....assign the reference properly. (Or) What is the proper syntax to assign
the reference by the name (have I missed assigning a property that would
allow it?)