|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
结果放在一张表上,请参考:
Sub ADO法()
Dim Fso As Object, File As Object, cnn As Object, SQL$, m&, n&, arr, brr(1 To 100000, -1 To 2), i&, j&
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
Set Fso = CreateObject("Scripting.FileSystemObject")
Set cnn = CreateObject("adodb.connection")
For Each File In Fso.GetFolder(CreateObject("scripting.filesystemobject").GetFolder(ThisWorkbook.Path).ParentFolder.Path & "\张庄乡八里村 旧表").Files
If File.Name Like "*.xls*" Then
n = n + 1
If n = 1 Then
cnn.Open "provider=microsoft.Ace.oledb.12.0;extended properties=excel 12.0;data source=" & File
SQL = "select * from [信息总表$b2:d13]"
Else
SQL = "select * from [Excel 12.0;Database=" & File & ";].[信息总表$b2:d13]"
End If
arr = cnn.Execute(SQL).GetRows
brr(m + 1, -1) = n
For i = 0 To UBound(arr, 2)
If IsNull(arr(0, i)) Then Exit For
m = m + 1
For j = 0 To 2
brr(m, j) = arr(j, i)
Next
Next
End If
Next
ActiveSheet.UsedRange.Offset(2).ClearContents
Range("A3").Resize(m, 4) = brr
cnn.Close
Set cnn = Nothing
Set File = Nothing
Set Fso = Nothing
Application.ScreenUpdating = True
End Sub
|
|