Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jun 2001
    Location
    Vancouver, Br. Columbia
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have several autotext entries saved in a template add-in. In another template's userform, I have a combobox that populates from the specified autotext entries in the add-in template (i.e. based on category). This works fine, except I want them to sort alphabetically and to display the first item on the list in the combobox. Currently, using the following code, the combobox displays blank and I have to click the down-arrow to see the entries. Also, they are not sorted, rather, they are in the order in which I created them.

    This is the code I'm using:
    Set MyTemplate = Templates(CorpStartTemp)

    Dim objDistList As BuildingBlock

    For i = 1 To MyTemplate.BuildingBlockTypes(wdTypeAutoText).Cate gories("DistLists").BuildingBlocks.Count
    Set objDistList = MyTemplate.BuildingBlockTypes(wdTypeAutoText).Cate gories("DistLists").BuildingBlocks(i)
    ToDlg.cboDistLists.AddItem objDistList.Name
    Next i

    CorpStartTemp - is my startup template
    ToDlg - is the form name in the other template
    cboDistList - is the name of the combobox control

    Can anyone help with (1) sorting them alphabetically, and (2) defaulting to display the first name in the list?

    Thanks...
    Adri

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can use code like this:

    Code:
    Dim arr() As String
    Dim i As Integer
    Dim n As Integer
    
    ...
    
    n = MyTemplate.BuildingBlockTypes(wdTypeAutoText).Categories("DistLists").BuildingBlocks.Count
    ' Fill array
    ReDim arr(1 To n)
    For i = 1 To n
      Set objDistList = MyTemplate.BuildingBlockTypes(wdTypeAutoText).Categories("DistLists").BuildingBlocks(i)
      arr(i) = objDistList.Name
    Next i
    ' Sort array
    WordBasic.SortArray arr
    With ToDlg.cboDistLists
      ' Populate combo box
      .List = arr
      ' And select first item
      .Value = .List(0)
    End With

  3. #3
    Star Lounger
    Join Date
    Jun 2001
    Location
    Vancouver, Br. Columbia
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans, I'll give it a try.
    Adri

Posting Permissions

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