- Makro skopíruje časť prvého pracovného hárka každého súboru, ktorý je v priečinku C: \ Data, do prvého pracovného hárka vášho zošita.
- Prvé makro skopíruje normálne a druhé makro skopíruje hodnoty.
Nezabudnite, že Excel má iba 256 stĺpcov
Sub CopyColumn () Dim basebook As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim Destrange As Range Dim cnum As Integer Dim i As Long Dim a As Integer Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = "C: \ Údaje ".SearchSubFolders = False .FileType = msoFileTypeExcelWorkbooks If .Execute ()> 0 Then set basebook = ThisWorkbook cnum = 1 For i = 1 To .FoundFiles.Count Set mybook = Workbooks.Open (.FoundFiles (i)) Set sourceRange = mybook.Worksheets (1) .Columns ("A: B") a = sourceRange.Columns.Count Set destrange = basebook.Worksheets (1) .Cells (1, cnum) sourceRange.Copy destrange mybook.Close cnum = i * a + 1 Ďalej i Koniec, ak skončí s Application.ScreenUpdating = True End Sub Sub CopyColumnValues () Dim basebook As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim distrange As Range Dim cnum As Integer Dim i as Long Dim a As Integer Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = "C: \ Data" .SearchSubFolders = False .FileType = msoFileTypeExcelWorkbooks If .Execute ()> 0 Then Set basebook = ThisWorkbook cnum = 1 For i = 1 To .FoundFiles.Count Set mybook = Workbooks.Open (.FoundFiles (i)) Set sourceRange = mybook.Worksheets ( 1). Stĺpce ("A: B") a = sourceRange.Columns.Count With sourceRange Set destrange = basebook.Worksheets (1) .Columns (cnum). _ Zmeniť veľkosť (, .Columns.Count) Koniec s destrange.Value = sourceRange.Value mybook.Close cnum = i * a + 1 Ďalej i End If End with Application.ScreenUpdating = True End Sub