Guest User

Untitled

a guest
Jun 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Public Sub createReport(book As Workbook, startRow As Long, folderPath As String)
  4. Dim outBook As Workbook
  5. Set outBook = Workbooks.Add
  6.  
  7.  
  8.  
  9. Dim finalName As String
  10. Randomize
  11. finalName = "test" & Rnd & ".xls"
  12. outBook.SaveAs Filename:=folderPath & finalName
  13. outBook.Close
  14. End Sub
  15.  
  16. Sub main()
  17. Application.ScreenUpdating = False
  18. Dim mainBook As Workbook
  19. Set mainBook = ThisWorkbook
  20.  
  21. Dim folderPath As String
  22. 'folderPath = "C:\Users\Àäìèíèñòðàòîð\Desktop\Test"
  23. folderPath = mainBook.Worksheets("main").Cells(3, 1).Value & "\"
  24. Dim sourceFile As String
  25. 'sourceFile = "data.csv"
  26. sourceFile = mainBook.Worksheets("main").Cells(6, 1).Value
  27.  
  28. If Dir(folderPath & sourceFile) = "" Then
  29. MsgBox ("Ôàéë " & folderPath & sourceFile & " íå íàéäåí!")
  30. Exit Sub
  31. End If
  32.  
  33. Dim csvBook As Workbook
  34. Set csvBook = Workbooks.Open(Filename:=folderPath & sourceFile, Delimiter:=";", Local:=True)
  35.  
  36. Dim startRow As Long
  37. startRow = 2
  38.  
  39. Dim endRow As Long
  40. Do
  41. endRow = csvBook.Sheets(1).Cells(startRow, 2).End(xlDown).Row 'startRow + 6
  42. createReport csvBook, startRow, folderPath
  43. startRow = endRow + 3
  44. Loop While csvBook.Sheets(1).Cells(startRow, 1).Value <> ""
  45.  
  46. csvBook.Close
  47. Application.ScreenUpdating = True
  48. End Sub
Add Comment
Please, Sign In to add comment