Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim configFileList As Variant 'Premenna pre cely modul
- Sub RefreshMultipleFiles()
- Call GetFileList
- Dim i As Integer
- i = 0
- Dim fileOZ As Workbook
- Dim folderOZ As String
- Dim targetSheet As Worksheet
- Dim targetRange As Range
- folderOZ = (Application.ThisWorkbook.Path & "/Users/")
- Do While (i < (UBound(configFileList) + 1) And Dir(folderOZ & configFileList(0)) <> "") 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/ubound-function
- 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/
- Set targetSheet = fileOZ.Sheets("Sheet1")
- Debug.Print ("OZ Filename[" & Format(Now, "hh:nn:ss") & "]: " & fileOZ.Name) 'Otvor si Immediate window (Ctrl+G) a uvidíš Debug.Print správy
- Set targetRange = targetSheet.Range("M4") 'https://stackoverflow.com/questions/11568321/writing-a-string-to-a-cell-in-excel
- targetRange.Value = 14
- fileOZ.RefreshAll
- fileOZ.Close (False)
- Debug.Print Format(Now, "hh:nn:ss") & " -> Success"
- i = i + 1
- Loop
- If Dir(folderOZ & configFileList(0)) = "" Then
- MsgBox ("Chyba v zozname súborov!" & vbNewLine & "i = " & i), (vbOKOnly + vbCritical)
- ElseIf UBound(configFileList) = 0 Then
- MsgBox ("Prázdny zoznam súborov"), (vbOKOnly + vbExclamation)
- Else
- MsgBox ("Hotovo :)" & vbNewLine & vbNewLine & UBound(configFileList) + 1) & " súborov bolo aktualizovanych"
- End If
- End Sub
- Sub GetFileList()
- Dim configFilePath As String
- Dim configWhole As String
- 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
- configFilePath = Application.ActiveWorkbook.Path & "\FileNameList.txt" 'Application.ActiveWorkbook.Path vráti cestu do zložky aktívneho workbooku
- 'alternativa Application.ThisWorkbook.Path vráti cestu ku zložke v ktorej je súbor s týmto makrom
- 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
- configWhole = Input$(LOF(1), 1) 'tiez neviem ako to funguje :(
- Close #1
- configFileList = Split(configWhole, vbNewLine) 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/split-function
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement