Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A-Z combo box (2000 / 2003)

    Hi,

    Is there a way of making a msoControlDropDown display A-Z instead of the order I typed the list in.

    Many thanks

    Set CtrlSpec = barSpec.Controls _
    .Add(Type:=msoControlDropdown)

    With CtrlSpec
    .AddItem "Apples"
    .AddItem "Pears"
    .AddItem "Bananas"
    .AddItem "Oranges"
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: A-Z combo box (2000 / 2003)

    You could use code like this:
    <code>
    Dim arr(1 To 4) As String
    Dim i As Integer

    ' Fill array with items
    arr(1) = "Apples"
    arr(2) = "Pears"
    arr(3) = "Bananas"
    arr(4) = "Oranges"

    ' Use good old WordBasic to sort the array
    WordBasic.SortArray arr

    ' Add items to dropdown
    With CtrlSpec
    For i = 1 To 4
    .AddItem arr(i)
    Next i
    End With</code>

  3. #3
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A-Z combo box (2000 / 2003)

    Thanks Hans, this was very useful.

    I have intergrated somthing else you taught me! Now I have the flexibility to easily change the combo without editing the VBA

    Many thanks

    Sub ComboTestToolbarArray()

    Const strSpec = "H:Spec.txt"
    Dim strLine() As String
    Dim f As Integer
    Dim i As Integer

    f = FreeFile
    Open strSpec For Input As #f
    Do While Not EOF(f)
    i = i + 1
    ReDim Preserve strLine(1 To i)
    Line Input #f, strLine(i)
    Loop
    Close #f

    WordBasic.SortArray strLine

    Set barSpec = CommandBars _
    .Add(Name:="SLSTEST", Position:=msoBarTop, _
    Temporary:=False)
    barSpec.Visible = True

    Set CtrlSpec = barSpec.Controls _
    .Add(Type:=msoControlDropdown)

    With CtrlSpec
    For i = 1 To i
    .AddItem strLine(i)
    Next i
    .Width = 170
    .DropDownWidth = -1
    End With

    End Sub
    Regards
    Gerbil (AKA Kevin)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •