Reikia naudoti VBA kodą, kuri dedame į excelio tuščios knygos lapo modulį(į knygą, kur surinkinėsime duomenis).
VBA kodas:
rašė:
Sub LapuSurinkimasViename()
Dim wsSh As Worksheet, oAwb As String, sSheetName As String, oFile
sSheetName = InputBox("Lapo pavadinimas iš kurio renkami duomenys(jei lapo pavadinimas nenurodomas-duomenys renkami iš visų knygos lapų)", "Nustatymai")
If sSheetName = "" Then sSheetName = "*"
On Error GoTo 0
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.InitialFileName = "*.*"
.Title = "Išsirenkame failus"
If .Show = False Then Exit Sub
For Each oFile In .SelectedItems
Workbooks.Open Filename:=oFile
oAwb = Dir(oFile, vbDirectory)
Application.ScreenUpdating = False
Workbooks(oAwb).Activate
For Each wsSh In Sheets
If wsSh.Name Like sSheetName Then
wsSh.Copy ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Mid$(oAwb, 1, InStr(oAwb, ".") - 1)
End If
Next wsSh
Workbooks(oAwb).Close False
Next oFile
End With
Application.ScreenUpdating = True
End Sub