Sub import_csv()
''This requires that you add a reference Microsoft ActiveX Data Objects to support the ADO code.
''also need to download & install Microsoft Access Database Engine 2010 Redistributable
''AccessDatabaseEngine_x64.exe
'' from http://www.microsoft.com/en-us/download/details.aspx?id=13255
'' you have to create a schema.ini file in the same directory
''[short.csv] the file name of the csv file
''Format=Delimited(*)
''ColNameHeader = True
''FirstRowHasNames = True
Dim con, rst
Set con = CreateObject("ADODB.Connection")
'' the directry name is Source
con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\sourcedir;Extended Properties='Text;HDR=YES;FMT=Delimited*';"
Set rst = CreateObject("ADODB.Recordset")
'' the csv file goes between the [brackets]
rst.Open "SELECT * FROM [short.csv] WHERE AccountNo=00009819;", con
Dim nextRow As Integer
rst.MoveFirst
nextRow = Worksheets("Sheet1").UsedRange.Rows.Count + 1
Worksheets("Sheet1").Cells(nextRow, 1).CopyFromRecordset rst
rst.Close
con.Close
Set rst = Nothing
Set con = Nothing
End Sub
Bookmarks