Sub GopDL()
Dim sFile, sArr, Res(), mainFile$
Dim n&, ik&, j&
On Error Resume Next
ReDim Res(1 To 6, 1 To 11)
sFile = GetFile(ThisWorkbook.Path)
If TypeName(sFile) = "Variant()" Then
mainFile = ThisWorkbook.Name
With CreateObject("ADODB.Connection")
For n = 1 To UBound(sFile)
If mainFile <> Right(sFile(n), Len(mainFile)) Then
sArr = Empty
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sFile(n) & ";Extended Properties=Excel 12.0"
sArr = .Execute("select * from [Si so$] where f2 is not null").GetRows
If IsNumeric(Mid(sArr(1, 1), 1, 1)) Then
ik = Mid(sArr(1, 1), 1, 1)
If ik >= 1 And ik <= 5 Then
For j = 2 To UBound(sArr, 1)
Res(ik, j - 1) = Res(ik, j - 1) + Val(sArr(j, 1))
Res(6, j - 1) = Res(6, j - 1) + Val(sArr(j, 1))
Next j
End If
End If
.Close
End If
Next n
End With
End If
Sheets("Sheet1").Range("C5").Resize(6, 11) = Res
End Sub
Private Function GetFile(ByVal strPath As String)
Dim Fldr As FileDialog, i&, Res
Set Fldr = Application.FileDialog(msoFileDialogFilePicker)
With Fldr
.AllowMultiSelect = True
.InitialFileName = strPath
.Filters.Add "Images", "*.xls*"
If .Show <> -1 Then GoTo NextCode
If .SelectedItems.Count = 1 Then
Res = Array("", .SelectedItems(1))
Else
ReDim Res(1 To .SelectedItems.Count)
For i = 1 To .SelectedItems.Count
Res(i) = .SelectedItems(i)
Next i
End If
End With
GetFile = Res
NextCode:
Set Fldr = Nothing
End Function