Solved

Excel VBA  - Input past end of file Error !!

Posted on 2013-06-26
4
1,102 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
  • 2
4 Comments
 
LVL 92

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 33

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now