|
Sub limonet()
Dim Cn As Object, StrSQL$, Path$, Filename$, Arr() As Variant, Brr() As Variant, CS As New Collection, i%, j%
Set Cn = CreateObject("Adodb.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Path = ThisWorkbook.Path & "\"
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
If Not Filename Like "*.xlsm" Then
CS.Add Filename
StrSQL = StrSQL & " Union All Select '" & Replace(Filename, ".", "' As Name,'") & _
"' As Ex,* From [Excel 12.0;Database=" & Path & Filename & "].[Export$A2:A]"
End If
Filename = Dir
Loop
StrSQL = "Select name,Ex,Count(*) From (" & Mid(StrSQL, 12) & ") Group By name,Ex"
Arr = Cn.Execute(StrSQL).GetRows
Brr = Application.Transpose(Application.Transpose(Cn.Execute(StrSQL).GetRows(, , "Name")))
For i = 1 To CS.Count
If UBound(Filter(Brr, Split(CS(i), ".xls")(0))) = -1 Then
j = UBound(Arr, 2) + 1
ReDim Preserve Arr(0 To UBound(Arr), 0 To j)
Arr(0, j) = Split(CS(i), ".")(0)
Arr(1, j) = Split(CS(i), ".")(1)
Arr(2, j) = 0
End If
Next i
Range("B3").Resize(i - 1, 3) = Application.Transpose(Arr)
End Sub |
|