PC Review


Reply
Thread Tools Rate Thread

ComboBox and multi sheets

 
 
E.Z.
Guest
Posts: n/a
 
      26th May 2009
Hi,
I have a workbook with many worksheets.
In each worksheet I'm using a ComboBox control with some values.
My question is - Should I define a ComboBox for each sheet or is there a way
to define one ComboBox and use it every time for the ActiveSheet?

Tnx


 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      26th May 2009
Objects like combo boxes are embeded in sheets so generally speaking you are
going to be better off to create one in each sheet. You can not create a
combo box that floats.
--
HTH...

Jim Thomlinson


"E.Z." wrote:

> Hi,
> I have a workbook with many worksheets.
> In each worksheet I'm using a ComboBox control with some values.
> My question is - Should I define a ComboBox for each sheet or is there a way
> to define one ComboBox and use it every time for the ActiveSheet?
>
> Tnx
>
>
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      26th May 2009
If you want to use a combobox on multiple sheets, then put it on a UserForm
and call the UserForm when you need the Combobox.

When you attach the Combobox to the sheet, it becomes a child of the sheet.
i.e. x = Sheets(1).ComboBox1.Value
And it is only visible on that sheet.


"E.Z." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I have a workbook with many worksheets.
> In each worksheet I'm using a ComboBox control with some values.
> My question is - Should I define a ComboBox for each sheet or is there a
> way to define one ComboBox and use it every time for the ActiveSheet?
>
> Tnx
>
>



 
Reply With Quote
 
ker_01
Guest
Posts: n/a
 
      26th May 2009
Try the following code to place a drop-down box on a toolbar that you can
hook into a macro (have the macro look to see what the value of the listbox
is, and use that in your processing). I commented out the extra code for
adding toolbar buttons, but you are welcome to adapt that if you need.

Public Const ToolbarName = "Test Toolbar"

Sub CreateToolbar()
Dim TBar As CommandBar
Dim NewDD As CommandBarControl
Dim NewBtn As CommandBarButton
Dim BeginThisGroup As Boolean

BeginThisGroup = False

'delete any previous old copy of the toolbar
On Error Resume Next
CommandBars(ToolbarName).Delete
On Error GoTo 0

'identify the starting position for placing the toolbar
OldToolBarTop = 0
For Each ctlCBarControl In Application.CommandBars
NewToolBarTop = ctlCBarControl.Top + ctlCBarControl.Height
If NewToolBarTop > OldToolBarTop Then OldToolBarTop = NewToolBarTop
Next

'define the Toolbar
Set TBar = CommandBars.Add
With TBar
..Name = ToolbarName
..Visible = True
..Position = 1
..Top = OldToolBarTop
End With

'TMacros = Array("Macro1", _
' "Macro2", _
' "Macro3")
'TToolTip = Array("Tooltip 1", _
' "Tooltip 2", _
' "Tooltip 3")
'TIcon = Array("Icon1", _
' "Icon2", _
' "Icon3")
'TMask = Array("mask1", _
' "mask2", _
' "mask3")
'
'ShowOrder = Array(1, 2, 3)
'
'For p = LBound(ShowOrder) To UBound(ShowOrder)
'If p = 2 Then BeginThisGroup = True Else BeginThisGroup = False
' i = ShowOrder(p)
' AddAButton TBar, TMacros(i), TToolTip(i), TIcon(i), TMask(i),
BeginThisGroup
'Next

With TBar
Set NewDD = .Controls.Add(Type:=msoControlComboBox, ID:=1)
With NewDD
.Caption = "I am caption"
.Style = msoComboNormal
.AddItem "* ALL *", 1
.AddItem "Option1", 2
.AddItem "Option2", 3
.AddItem "Option3", 4
.ListIndex = 1
.OnAction = "Macro4"
End With
End With

End Sub

Sub AddAButton(ByVal TBar As CommandBar, ByVal MacroName As String, ByVal
uToolTip As String, ByVal uShape As String, ByVal uMask As String, BTG As
Boolean)
'AddAButton(CommandBar, MacroName, ToolTip, Icon, Mask, separatorbar)

Set NewBtn = TBar.Controls.Add(Type:=msoControlButton)
With NewBtn
..BeginGroup = BTG
..OnAction = MacroName
..Style = msoButtonIcon
SetIcon NewBtn, Sheet17.Shapes(uShape), Sheet17.Shapes(uMask)
..TooltipText = uToolTip
..Visible = True
End With

End Sub


"E.Z." wrote:

> Hi,
> I have a workbook with many worksheets.
> In each worksheet I'm using a ComboBox control with some values.
> My question is - Should I define a ComboBox for each sheet or is there a way
> to define one ComboBox and use it every time for the ActiveSheet?
>
> Tnx
>
>
>

 
Reply With Quote
 
E.Z.
Guest
Posts: n/a
 
      27th May 2009
IC, Tnx

"Jim Thomlinson" <James_Thomlinson@owfg-Re-Move-This-.com> wrote in message
news:A5D96EC1-2335-4288-8306-(E-Mail Removed)...
> Objects like combo boxes are embeded in sheets so generally speaking you
> are
> going to be better off to create one in each sheet. You can not create a
> combo box that floats.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "E.Z." wrote:
>
>> Hi,
>> I have a workbook with many worksheets.
>> In each worksheet I'm using a ComboBox control with some values.
>> My question is - Should I define a ComboBox for each sheet or is there a
>> way
>> to define one ComboBox and use it every time for the ActiveSheet?
>>
>> Tnx
>>
>>
>>



 
Reply With Quote
 
E.Z.
Guest
Posts: n/a
 
      27th May 2009
Tnx,
I didn't want to use a UserFrom 'cause it will show the dialog frame as
well.


"JLGWhiz" <(E-Mail Removed)> wrote in message
news:u3%(E-Mail Removed)...
> If you want to use a combobox on multiple sheets, then put it on a
> UserForm and call the UserForm when you need the Combobox.
>
> When you attach the Combobox to the sheet, it becomes a child of the
> sheet. i.e. x = Sheets(1).ComboBox1.Value
> And it is only visible on that sheet.
>
>
> "E.Z." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>> I have a workbook with many worksheets.
>> In each worksheet I'm using a ComboBox control with some values.
>> My question is - Should I define a ComboBox for each sheet or is there a
>> way to define one ComboBox and use it every time for the ActiveSheet?
>>
>> Tnx
>>
>>

>
>



 
Reply With Quote
 
E.Z.
Guest
Posts: n/a
 
      27th May 2009
Tnx for the useful code,
I tested it and found out that I have no much control on such a ListBox. For
ex. - only Change event is available, no RTL alignment etc.
Anyway, was very useful to learn it.

"ker_01" <(E-Mail Removed)> wrote in message
news:AF6BB864-0808-47EC-A3C3-(E-Mail Removed)...
> Try the following code to place a drop-down box on a toolbar that you can
> hook into a macro (have the macro look to see what the value of the
> listbox
> is, and use that in your processing). I commented out the extra code for
> adding toolbar buttons, but you are welcome to adapt that if you need.
>
> Public Const ToolbarName = "Test Toolbar"
>
> Sub CreateToolbar()
> Dim TBar As CommandBar
> Dim NewDD As CommandBarControl
> Dim NewBtn As CommandBarButton
> Dim BeginThisGroup As Boolean
>
> BeginThisGroup = False
>
> 'delete any previous old copy of the toolbar
> On Error Resume Next
> CommandBars(ToolbarName).Delete
> On Error GoTo 0
>
> 'identify the starting position for placing the toolbar
> OldToolBarTop = 0
> For Each ctlCBarControl In Application.CommandBars
> NewToolBarTop = ctlCBarControl.Top + ctlCBarControl.Height
> If NewToolBarTop > OldToolBarTop Then OldToolBarTop = NewToolBarTop
> Next
>
> 'define the Toolbar
> Set TBar = CommandBars.Add
> With TBar
> .Name = ToolbarName
> .Visible = True
> .Position = 1
> .Top = OldToolBarTop
> End With
>
> 'TMacros = Array("Macro1", _
> ' "Macro2", _
> ' "Macro3")
> 'TToolTip = Array("Tooltip 1", _
> ' "Tooltip 2", _
> ' "Tooltip 3")
> 'TIcon = Array("Icon1", _
> ' "Icon2", _
> ' "Icon3")
> 'TMask = Array("mask1", _
> ' "mask2", _
> ' "mask3")
> '
> 'ShowOrder = Array(1, 2, 3)
> '
> 'For p = LBound(ShowOrder) To UBound(ShowOrder)
> 'If p = 2 Then BeginThisGroup = True Else BeginThisGroup = False
> ' i = ShowOrder(p)
> ' AddAButton TBar, TMacros(i), TToolTip(i), TIcon(i), TMask(i),
> BeginThisGroup
> 'Next
>
> With TBar
> Set NewDD = .Controls.Add(Type:=msoControlComboBox, ID:=1)
> With NewDD
> .Caption = "I am caption"
> .Style = msoComboNormal
> .AddItem "* ALL *", 1
> .AddItem "Option1", 2
> .AddItem "Option2", 3
> .AddItem "Option3", 4
> .ListIndex = 1
> .OnAction = "Macro4"
> End With
> End With
>
> End Sub
>
> Sub AddAButton(ByVal TBar As CommandBar, ByVal MacroName As String, ByVal
> uToolTip As String, ByVal uShape As String, ByVal uMask As String, BTG As
> Boolean)
> 'AddAButton(CommandBar, MacroName, ToolTip, Icon, Mask, separatorbar)
>
> Set NewBtn = TBar.Controls.Add(Type:=msoControlButton)
> With NewBtn
> .BeginGroup = BTG
> .OnAction = MacroName
> .Style = msoButtonIcon
> SetIcon NewBtn, Sheet17.Shapes(uShape), Sheet17.Shapes(uMask)
> .TooltipText = uToolTip
> .Visible = True
> End With
>
> End Sub
>
>
> "E.Z." wrote:
>
>> Hi,
>> I have a workbook with many worksheets.
>> In each worksheet I'm using a ComboBox control with some values.
>> My question is - Should I define a ComboBox for each sheet or is there a
>> way
>> to define one ComboBox and use it every time for the ActiveSheet?
>>
>> Tnx
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi column Combobox Charles G via AccessMonster.com Microsoft Access Forms 11 13th Sep 2005 05:51 PM
Multi-column combobox Paul Johnston Microsoft Outlook Form Programming 0 9th Aug 2005 09:39 PM
THE Multi Column ComboBox DraguVaso Microsoft ADO .NET 27 20th Jun 2005 01:38 PM
multi select combobox mcnewsxp Microsoft Access Form Coding 6 12th Dec 2004 06:46 PM
Multi selection using combobox Naresh Microsoft Access Form Coding 0 11th Jul 2003 01:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:40 AM.