Hi Boreq, that worked, thanks for the help I appreciate it.
Des
Main Topics
Browse All TopicsHi I presently have a difficulty with importing csv files into excel using VBA. I have created a macro which is meant to read each record from a csv file and put it into excel. The code also needs to handle the splitting into different sheets when the csv file has more than the allowed 65536 rows. Can you please help. My code is ignoring the first record, thus not bringing back all records. code below.
'Imports text file into Excel workbook using ADO.
'If the number of records exceeds 65536 then it splits it over more than one sheet.
Dim strFilePath As String, strFilename As String, strFullPath As String
Dim lngCounter As Long
Dim oConn As Object, oRS As Object, oFSObj As Object
'Get a text file name
strFullPath = Application.GetOpenFilenam
If strFullPath = "False" Then Exit Sub 'User pressed Cancel on the open file dialog
'This gives us a full path name e.g. C:tempfolderfile.txt
'We need to split this into path and file name
Set oFSObj = CreateObject("SCRIPTING.FI
strFilePath = oFSObj.GetFile(strFullPath
strFilename = oFSObj.GetFile(strFullPath
'Open an ADO connection to the folder specified
Set oConn = CreateObject("ADODB.CONNEC
oConn.Open "Provider=Microsoft.Jet.OL
"Data Source=" & strFilePath & ";" & _
"Extended Properties=""text;HDR=Yes;
Set oRS = CreateObject("ADODB.RECORD
'Now actually open the text file and import into Excel
oRS.Open "SELECT * FROM " & strFilename, oConn, 3, 1, 1
While Not oRS.EOF
Sheets.Add
ActiveSheet.Range("A1").Co
Wend
oRS.Close
oConn.Close
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi PKS6A, welcome to Experts Exchange!
It seems that boreg supplied you with a satisfactory answer, so please accept his comment as an answer, and grade it accordingly, so the question becomes closed. This is the process that helps keep EE cleaner, and prevents the moderators from having to step in.
Thanks, and we hope to see you round!
Regards,
Rob.
Hi All,
I added this to Excel as a macro and it woks, but I would like the marco to loop and pick up all the CSV file in my Audit directory, so that one spreadsheet holds all details of my audits.
Please can some one explain how to loop this, or to select all csv files in one location and import them into on spreadsheet.
Hi there, I'm brand new to EE and was wondering if the Open Discussion from Technical-ZA for thsi thread has been answered anywhere?
I have a directory full of identically formatted csv files that I need to import as text files (Column A is 17 characters long and needs to be actually imported as text and not just copied as a number). I need all the data from the individual csv files to end up in a single worksheet.
Any help would be very much appreciated.
Business Accounts
Answer for Membership
by: boregPosted on 2008-04-22 at 10:14:15ID: 21413279
Hi, try changing HDR=Yes to HDR=No