|
Sub ADO法汇总()
Dim Cat As Object, Tbl As Object, strCnn As String, t As String
Set Cat = CreateObject("ADOX.Catalog")
Dim Fso As Object, Folder As Object, arr$(), m&, Cnn As Object, SQL$, i&
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Folder = Fso.GetFolder(ThisWorkbook.Path)
Application.ScreenUpdating = False
Call GetFiles(Folder, arr, m)
Set Cnn = CreateObject("adodb.connection")
strCnn = "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source="
Cnn.Open strCnn & ThisWorkbook.FullName
ActiveSheet.UsedRange.Offset(1).ClearContents
For i = 1 To m
Cat.ActiveConnection = strCnn & arr(i)
For Each Tbl In Cat.Tables
If Tbl.Type = "TABLE" Then
t = Replace(Tbl.Name, "'", "")
If Right(t, 1) = "$" Then
If t Like "*导出*" Then
SQL = "select * from [Excel 12.0;Database=" & arr(i) & ";].[" & t & "]"
Range("a" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset Cnn.Execute(SQL)
End If
End If
End If
Next
Next
Set Cat = Nothing
Set Folder = Nothing
Set Fso = Nothing
Cnn.Close
Set Cnn = Nothing
Set File = Nothing
Set Fso = Nothing
Application.ScreenUpdating = True
End Sub |
|