[RESOLVED] [2005] Late Binding
I'm opening an Excel file and using the header row to fill a list box.
The code below works until I turn on the project setting to disallow late binding. Then line in bold is producing a problem. Is there an easier way to do what I want without having to turn off the late binding warning/error?
Code:
Dim strList As String = ""
Dim i As Integer = 1
Dim oSht As New Excel.Worksheet
Dim oWB As Excel.Workbook
Try
'Create an Excel instance.
oApp = New Excel.Application
oWB = oApp.Workbooks.Open("c:\temp\test.xls")
oSht = CType(oWB.ActiveSheet, Excel.Worksheet)
Do
strList = CType(oSht.Cells(1, i).value, String)
If strList = "" Then
Exit Do
End If
lstAllVars.Items.Add(strList)
i = i + 1
Loop While strList <> ""
'close and clean up resources
oApp.Quit()
oApp = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try