Guest User

Untitled

a guest
Nov 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. Sub GetMyCSVData()
  2. Dim xlcon As ADODB.Connection
  3. Dim xlrs As ADODB.Recordset
  4.  
  5. Set xlcon = New ADODB.Connection
  6. Set xlrs = New ADODB.Recordset
  7.  
  8. Dim currentDataFilePath As String
  9. Dim currentDataFileName As String
  10. Dim nextRow As Integer
  11.  
  12. currentDataFilePath = "C:\Users\thaobt.acc\Desktop\"
  13. currentDataFileName = "CreCSSV"
  14.  
  15. xlcon.Provider = "Microsoft.Jet.OLEDB.4.0"
  16. xlcon.ConnectionString = "Data Source=" & currentDataFilePath & ";" & "Extended Properties=""text;HDR=Yes;FMT=Delimited;"""
  17.  
  18. xlcon.Open
  19.  
  20. xlrs.Open "SELECT Voucher,Quantity,Price,Total FROM [" & currentDataFileName & ".csv] WHERE Price > 200", xlcon
  21. xlrs.MoveFirst
  22. nextRow = Worksheets("Sheet3").UsedRange.Rows.Count + 1
  23. Worksheets("Sheet3").Cells(nextRow, 1).CopyFromRecordset xlrs
  24.  
  25. xlrs.Close
  26. xlcon.Close
  27.  
  28. Set xlrs = Nothing
  29. Set xlcon = Nothing
  30. End Sub
Add Comment
Please, Sign In to add comment