Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. Dim strSourcePath As String
  2. Dim strDestPath As String
  3. Dim strFile As String
  4. Dim strData As String
  5. Dim x As Variant
  6. Dim Cnt As Long
  7. Dim r As Long
  8. Dim c As Long
  9.  
  10. Application.ScreenUpdating = False
  11.  
  12. 'Change the path to the source folder accordingly
  13. strSourcePath = "C:UsersxxxxDocumentstest"
  14.  
  15. If Right(strSourcePath, 1) <> "" Then strSourcePath = strSourcePath & ""
  16.  
  17. 'Change the path to the destination folder accordingly
  18. strDestPath = "C:UsersxxxxDocumentstest1"
  19.  
  20. If Right(strDestPath, 1) <> "" Then strDestPath = strDestPath & ""
  21.  
  22. strFile = Dir(strSourcePath & "*.csv")
  23.  
  24. Do While Len(strFile) > 0
  25. Cnt = Cnt + 1
  26. r = Cells(Rows.Count, "A").End(xlUp).Row + 1
  27. Open strSourcePath & strFile For Input As #1
  28. Do Until EOF(1)
  29. Line Input #1, strData
  30. x = Split(strData, ",")
  31. For c = 0 To UBound(x)
  32. Cells(r, c + 1).Value = Trim(x(c))
  33. Next c
  34. r = r + 1
  35. Loop
  36. Close #1
  37. Name strSourcePath & strFile As strDestPath & strFile
  38. strFile = Dir
  39. Loop
  40.  
  41. Application.ScreenUpdating = True
  42.  
  43. If Cnt = 0 Then _
  44. MsgBox "No CSV files were found...", vbExclamation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement