Lezen uit cellen excel

Status
Niet open voor verdere reacties.

harolda1980

Gebruiker
Lid geworden
7 aug 2007
Berichten
488
Ik wil een enkele cel lezen uit een excel bestand.
Alleen ik krijg de waarden er op geen mogelijkheid uit.

Kan iemand mij hier mee helpen?

Code:
    Private Sub Main()

        Dim Proceed As Boolean = False
        Dim xlApp As Excel.Application = Nothing
        Dim xlWorkBooks As Excel.Workbooks = Nothing
        Dim xlWorkBook As Excel.Workbook = Nothing
        Dim xlWorkSheet As Excel.Worksheet = Nothing
        Dim xlWorkSheets As Excel.Sheets = Nothing
        Dim xlCells As Excel.Range = Nothing
        Dim k As Long = 1
        Dim i As Long = 1
        xlApp = New Excel.Application
        xlApp.DisplayAlerts = False
        xlWorkBooks = xlApp.Workbooks
        xlWorkBook = xlWorkBooks.Open(txtbestandslocatie.Text)
        xlApp.Visible = True
        ' xlWorkSheets = xlWorkBook.Sheets(1)


        Do
            Import_landen(xlWorkBook.Sheets(1).Cells(k, i))
            k = k + 1
        Loop
        xlWorkBook.Close()
        xlApp.UserControl = True
        xlApp.Quit()
        ReleaseComObject(xlCells)
        ReleaseComObject(xlWorkSheets)
        ReleaseComObject(xlWorkSheet)
        ReleaseComObject(xlWorkBook)
        ReleaseComObject(xlWorkBooks)
        ReleaseComObject(xlApp)

    End Sub
 
Laat eerst ook even weten wat er precies in txtbestandslocatie.Text staat.
 
Dat snap ik, maar een voorbeeld is wel op z'n plaats. Daarom vroeg ik het even precies aan te geven.
 
Ok dan. En heb je de waarden alleen in de routine Import_landen niet of zie je ze in de Main routine al niet?
 
Ik wil eigenlijk de waarden uit de cel doorsturen naar Import_landen.
Daarin handel ik af of de waarden bestaat zo ja. En in welke vorm. En zo niet dan word hij toegevoegd.
Alleen dan moet ik wel de waarden uit het excelbestand de cellen kunnen pakken.
 
Ik begrijp de bedoeling, maar dat is geen antwoord op de vraag die ik stelde. De vraag is dus of je die waarden in de Main routine al wel of niet hebt.
 
Ja die waarden zou ik daar wel al willen hebben. Tenminste dat was mijn bedoeling.
 
Ik ben een stuk verder wat er nu alleen gebeurd is dat als de cell leeg is. Dan krijg ik een Nullreferenceexeption.
Hoe kan ik die afhandelen. zodat wanneer er geen waarden uit een cell komt dat hij stopt met uitlezen?

Code:
        Dim Proceed As Boolean = False
        Dim xlApp As Excel.Application = Nothing
        Dim xlWorkBooks As Excel.Workbooks = Nothing
        Dim xlWorkBook As Excel.Workbook = Nothing
        Dim xlWorkSheet As Excel.Worksheet = Nothing
        Dim xlWorkSheets As Excel.Sheets = Nothing
        Dim xlCells As Excel.Range = Nothing
        Dim k As Long = 1
        Dim i As Long = 1
        xlApp = New Excel.Application
        xlApp.DisplayAlerts = False
        xlWorkBooks = xlApp.Workbooks
        xlWorkBook = xlWorkBooks.Open(txtbestandslocatie.Text)
        xlApp.Visible = True
        ' xlWorkSheets = xlWorkBook.Sheets(1)


        Do
            If IsError(xlWorkBook.Sheets(1).Cells(k, i).value.ToString) = True Then
                Exit Do
            Else
                Import_landen(xlWorkBook.Sheets(1).Cells(k, i).value.ToString)
            End If

            k = k + 1
        Loop
        xlWorkBook.Close()
        xlApp.UserControl = True
        xlApp.Quit()
        ReleaseComObject(xlCells)
        ReleaseComObject(xlWorkSheets)
        ReleaseComObject(xlWorkSheet)
        ReleaseComObject(xlWorkBook)
        ReleaseComObject(xlWorkBooks)
        ReleaseComObject(xlApp)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan