Advertisement
Johniny

in progress - Open/close loop

Mar 7th, 2020
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim configFileList As Variant 'Premenna pre cely modul
  2.  
  3. Sub RefreshMultipleFiles()
  4.  
  5. Call GetFileList
  6.  
  7. Dim i As Integer
  8. i = 0
  9. Dim fileOZ As Workbook
  10. Dim folderOZ As String
  11.  
  12. 'Do While configFileList(i) <> ""     - toto nefungovalo dobre, lebo neexistujúcu položku v arrayi nepovažuje za empty string ani za null
  13. Do While i < (UBound(configFileList) + 1) 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/ubound-function
  14.    folderOZ = (Application.ThisWorkbook.Path & "/Users/")
  15.     Set fileOZ = Workbooks.Open(folderOZ & configFileList(i)) 'https://www.mrexcel.com/board/threads/vba-code-loop-through-named-list-or-all-xls-files-in-a-directory.845397/
  16.    Debug.Print ("OZ Filename[" & Format(Now, "hh:nn:ss") & "]: " & fileOZ.Name) 'Otvor si Immediate window (Ctrl+G) a uvidíš Debug.Print správy
  17.    
  18.     'I can do here whatever I want
  19.    
  20.     fileOZ.Close
  21.     Debug.Print Format(Now, "hh:nn:ss") & " -> Success"
  22.     i = i + 1
  23. Loop
  24.  
  25.  
  26. End Sub
  27.  
  28. Sub GetFileList()
  29.  
  30. Dim configFilePath As String
  31. Dim configWhole As String
  32. Dim configArray As Variant 'nebude to fungovat so String ťhttps://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/data-type-summary
  33.  
  34. configFilePath = Application.ActiveWorkbook.Path & "\FileNameList.txt" 'Application.ActiveWorkbook.Path vráti cestu do zložky aktívneho workbooku
  35.    'alternativa Application.ThisWorkbook.Path vráti cestu ku zložke v ktorej je súbor s týmto makrom
  36. Open configFilePath For Input As #1 'netusim ako funguje Open+Input+Close :(, viac info na https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/line-inputstatement
  37. configWhole = Input$(LOF(1), 1) 'tiez neviem ako to funguje :(
  38. Close #1
  39. configFileList = Split(configWhole, vbNewLine) 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/split-function
  40.  
  41. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement