Solved

Excel VBA  - Input past end of file Error !!

Posted on 2013-06-26
4
1,153 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 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 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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

734 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