Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

Excel VBA - Input past end of file Error !!

VBA Code reads CSV file which i try to Import to an Excel Sheet. I am able to import a CSV file but getting an exception error on another file.

While FileTextStream.ReadLine <> "Invoice Date,Invoice Number,Account Number,DEA Number,Sales Rep,,,,,,,,,,"
 Wend

Open in new window


Error :

Run-time error '62':
Input past end of file
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

Function reads row by row from CSV file and get the data.

And (Not FileTextStream.AtEndOfStream) - Doesn't work.

I have attached csv file to import Excel. Button event in the excel to import the csv file.


Private Function GetInvoiceHeader() As InvoiceHeader
    Dim HeaderFields() As String
    
    While FileTextStream.ReadLine <> "Invoice Date,Invoice Number,Account Number,DEA Number,Sales Rep,,,,,,,,,,"

    Wend
    
   HeaderFields = Split(FileTextStream.ReadLine, ",")
         
          
    GetInvoiceHeader.Invoice_Date = CDate(HeaderFields(0))
    GetInvoiceHeader.Invoice_Number = CLng(HeaderFields(1))
    GetInvoiceHeader.Account_Number = CLng(HeaderFields(2))
    GetInvoiceHeader.DEA_Number = HeaderFields(3)
    GetInvoiceHeader.Sales_Rep = CLng(HeaderFields(4))

End Function

Open in new window

Test-6619289--5-30-2013.csv
ImportCSV.xls
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

@imnorie, Yes that code works fine.
I used a test file TestFile.csv

When I try to import actual file which is on the same format, i am facing the error FileStream End Error.