Sub TongHop_HLMT()
Dim strPath As Variant, strSQL As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Add "Excel Files", "*.xls*", 1
If Not .Show = -1 Then
MsgBox "Ban da khong chon tong hop", vbInformation, "Thông Báo"
Exit Sub
End If
For Each strPath In .SelectedItems
strSQL = strSQL & " Union All Select [Code],[Name],[Group],[SubTotal] From [EXCEL 12.0;Database=" & strPath & "].[TongKet$] Where [Name] Is Not Null"
Next
End With
With CreateObject("ADODB.Connection")
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=Excel 12.0 Xml;"
Sheet5.Range("E2").CopyFromRecordset .Execute("Select [Code],[Name],[Group],Sum(SubTotal) From (" & Right(strSQL, Len(strSQL) - 10) & ") Group By [Code],[Name],[Group]")
End With
End Sub