Hello everyone
I have this code that imports data from CSV file using ADO ..
'Reference : Microsoft ActiveX Data Objects 6.1 Library
'------------------------------------------------------
Sub GetCSVDataByADOConnection()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim folderPath As String
Dim fileName As String
Dim strCon As String
Dim i As Long
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
folderPath = ThisWorkbook.Path & "\"
fileName = "SampleCSV"
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.ConnectionString = "Data Source=" & folderPath & ";" & "Extended Properties=""text;HDR=Yes;FMT=Delimited;"""
conn.Open
strCon = "SELECT * FROM [" & fileName & ".csv]"
Set rs = conn.Execute(strCon)
If Not rs.EOF Then
Sheets("Sheet1").Range("A1").CopyFromRecordset rs
rs.Close
Else
MsgBox "Error: No Records Returned.", vbCritical
End If
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
End Sub
The csv file name is "SampleCSV" and this file has no headers .. It contains 6 rows from row 1 to row 6
When executing this code it works well but it imports five rows only from row 2 to row 6 skipping row 1
How can I edit the code so as to import row 1 too ... so I need to import the 6 rows (from row 1 to the last row which is row 6)?
Thanks advanced for help
Bookmarks