|
Sub limonet()
Dim Cn As Object, StrSQL$, Path$, FileName$, Cat As Object, ObjTable As Object
Set Cn = CreateObject("ADODB.Connection")
Set Cat = CreateObject("adox.catalog")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Path = ThisWorkbook.Path & "\"
FileName = Dir(Path & "*.xlsx")
Do While FileName <> ""
Cat.activeconnection = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & Path & FileName
For Each ObjTable In Cat.tables
If ObjTable.Name Like "*教基3113*" And Not ObjTable.Name Like "*xlnm*" Then
StrSQL = StrSQL & " Union All Select '" & Split(FileName, ".")(0) & "',Null,Null,* From [Excel 12.0;Hdr=no;Database=" & Path & FileName & "].[" & ObjTable.Name & "D6:D6]"
End If
Next ObjTable
FileName = Dir
Loop
Range("B2").CopyFromRecordset Cn.Execute(Mid(StrSQL, 12))
End Sub |
评分
-
1
查看全部评分
-
|