Reading Excel file into Combo Box

VBnewcomer
VBnewcomer used Ask the Experts™
on
I need my program to read an Excel file and insert contents of a column into a combo or list box. VB gurus out there..HELP!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
'Set a reference to the excel Library
On error goto Err
Dim Wksheet
Dim Excel
Dim x
Dim FileName as string
FileName = 'Put the location of excel file here
combo1.Clear
'Creates excel if open if not created in error handler
Set Excel = GetObject(, "Excel.Application")
Set x = Excel.Workbooks.Open(FileName)
Set Wksheet = x.Worksheets(1)
Excel.Visible = False
Excel.DisplayAlerts = False

Dim x as double
   For x = 1 to 10000 'these are the rows to go through
If Trim(Wksheet.Cells(x,1).Value) <> "" then 'see if cell
'is blank if it is blank then you are done if not
'add it to the combo
 combo1.additem Trim(Wksheet.Cells(x,1))
Else
Exit For
Next





Exit Sub
Err:
If Err.Number = 429 Then
    Set Excel = CreateObject("Excel.Application")
   
   Resume Next
Else
  Msgbox err.number & " " & err.description
End if

Author

Commented:
Thaaaannnxxxx!!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial