Solved

Excel VBA  - Input past end of file Error !!

Posted on 2013-06-26
4
1,164 Views
Last Modified: 2013-06-27
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
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 39279793
Try:

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

Open in new window

0
 

Author Comment

by:chokka
ID: 39279843
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
 
LVL 34

Assisted Solution

by:Norie
Norie earned 250 total points
ID: 39279859
Your code runs fine for me on that file.

Why not open the file in Excel and then deal with the data?
0
 

Author Comment

by:chokka
ID: 39279997
@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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question