|
Sub limonet()
Dim Cn As Object, StrSQL$, CS$
Set Cn = CreateObject("Adodb.Connection")
CS = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
Path = ThisWorkbook.Path & "\"
Filename = Dir(Path & "*.xlsx")
Do While Filename <> ""
Cn.Open CS & Path & Filename
If Cn.OpenSchema(20, Array(Empty, Empty, "xx01$", Empty)).EOF = False Then
StrSQL = StrSQL & " Union All Select * From [Excel 12.0;DataBase=" & Path & Filename & "].[xx01$]"
End If
Cn.Close
Filename = Dir
Loop
Cn.Open CS & ThisWorkbook.FullName
Set Rst = Cn.Execute(Mid(StrSQL, 12))
For j = 0 To Rst.Fields.Count - 1
Cells(1, j + 1) = Rst.Fields(j).Name
Next j
Range("A2").CopyFromRecordset Rst
End Sub
|
评分
-
1
查看全部评分
-
|