none
word 2003 RRS feed

  • Question

  • is it posible to create a combobox with 2 columns using  word 2003? If yes, how initialize it with vba?

    thank's for all

    • Moved by Ciprian Duduiala Tuesday, February 21, 2012 8:25 AM not in French (From:Développement VBA)
    Friday, February 17, 2012 10:44 PM

Answers

  • here is an example, the data source is the Table(1) of the document,
     
    voici un exemple, la source de données est la Table(1) du document,
     Private Sub UserForm_Initialize()
    Set rng = ActiveDocument.Tables(1)
    Me.ComboBox1.ColumnCount = 2
       For i = 0 To ActiveDocument.Tables(1).Columns(1).Cells.Count - 1
           Me.ComboBox1.AddItem
           Me.ComboBox1.List(i, 0) = rng.Columns(1).Cells(i + 1).Range.Text
           Me.ComboBox1.List(i, 1) = rng.Columns(2).Cells(i + 1).Range.Text
       Next
     
    End Sub
     --
    isabelle
     
     
    Saturday, February 18, 2012 1:55 AM

All replies

  • hi Molly,
     
    Here is an excerpt from using XL2002
     ================================================== =================================
     In a ListBox or ComboBox consists of a single column,
     AddItem method provides an effective technique to add individual entries to the list.
     However, in a multicolumn ListBox or ComboBox,
     List and Column properties offer another technique:
     you can load the list from a two-dimensional array.
     ================================================== =================================
     
    what remains to know is where is the data to feed the ComboBox ?
    the data is in a table in this document or elsewhere
     
    --
    isabelle
     
    Le 2012-02-17 17:44, molly1932 a écrit :
    > is it posible to create a combobox with 2 columns using word 2003? If yes, how initialize it with vba?
    >
    > thank's for all
    >
     
    Saturday, February 18, 2012 12:47 AM
  • here is an example, the data source is the Table(1) of the document,
     
    voici un exemple, la source de données est la Table(1) du document,
     Private Sub UserForm_Initialize()
    Set rng = ActiveDocument.Tables(1)
    Me.ComboBox1.ColumnCount = 2
       For i = 0 To ActiveDocument.Tables(1).Columns(1).Cells.Count - 1
           Me.ComboBox1.AddItem
           Me.ComboBox1.List(i, 0) = rng.Columns(1).Cells(i + 1).Range.Text
           Me.ComboBox1.List(i, 1) = rng.Columns(2).Cells(i + 1).Range.Text
       Next
     
    End Sub
     --
    isabelle
     
     
    Saturday, February 18, 2012 1:55 AM