Consulting

Results 1 to 4 of 4

Thread: Add contents of cells to combo box

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    61
    Location

    Add contents of cells to combo box

    I have a word doc with a combo box.
    I am trying to populate the box with the contents of column A.
    The amount of rows used varies.

    I triesdto just add the data from A1 to start with but I could'nt even manage that.

    here is my try
    the following code is held held on my word userform


    Workbook.open ("C:\test.xls.)
    cbxsup.additem Workbooks("C:\test.xls.).Sheets("Sheet1").Range("A,1")

  2. #2
    You could try something like :-
    Public Sub ImportFromExcelLateBinding()
    Dim xl As Object
    Dim wb As Object
    Dim ws As Object
    Dim LastRow As Long
    Dim Counter As Long
    Set xl = CreateObject("Excel.Application")
    Set wb = xl.workbooks.Open("C:\Test.xls")
    Set ws = wb.worksheets("Sheet1")
    LastRow = ws.Range("A" & ws.Rows.Count).End(3).Row
    Me.cmbTest.Clear
    For Counter = 1 To LastRow
            Me.cmbTest.AddItem CStr(ws.Range("A" & Counter).Value), Counter - 1
    Next Counter
    wb.Saved = True
    wb.Close
    xl.Quit
    Set ws = Nothing
    Set wb = Nothing
    Set xl = Nothing
    End Sub
    Assuming this code is in the document module, your combo is called cmbTest and the list is in Sheet1 Range A1 downwards of c:\test.xls.

    HTH
    Carl

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    CarlMack?

    I only know one person in Cyprus. Don't tell me that OzGrid has banned you as well?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    LOL . No Oz still puts up with me but I just saw a link here and thought I'd take a look around. I see you have been here for quite a while !

Posting Permissions

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