Public Sub QueryTextFile()
Dim Recordset As ADODB.Recordset
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & ";" & _
"Extended Properties=Text;"
Const SQL As String = "SELECT * FROM Sales.csv WHERE Type='Art';"
Set Recordset = New ADODB.Recordset
Call Recordset.Open(SQL, ConnectionString, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText)
Call Sheet1.Range("A1").CopyFromRecordset(Recordset)
Recordset.Close
Set Recordset = Nothing
End Sub
|