Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1202
  • Last Modified:

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
0
chokka
Asked:
chokka
  • 2
2 Solutions
 
Patrick MatthewsCommented:
Try:

While (FileTextStream.ReadLine <> "Invoice Date,Invoice Number,Account Number,DEA Number,Sales Rep,,,,,,,,,,") And (Not FileTextStream.AtEndOfStream)
 Wend

Open in new window

0
 
chokkaAuthor Commented:
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
0
 
NorieCommented:
Your code runs fine for me on that file.

Why not open the file in Excel and then deal with the data?
0
 
chokkaAuthor Commented:
@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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now