|
ADO法速度较快:- Sub Macro1()
- Dim Fso As Object, File As Object, cnn As Object, SQL$, m&
- Application.ScreenUpdating = False
- Set Fso = CreateObject("Scripting.FileSystemObject")
- ActiveSheet.UsedRange.Offset(3).ClearContents
- ActiveSheet.UsedRange.Offset(2, 1).ClearContents
- For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
- If File.Name Like "*.xls" And File.Name <> ThisWorkbook.Name Then
- m = m + 1
- If m = 1 Then
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no';Data Source=" & File
- SQL = "select * from [清算表$a3:b]"
- [a4].CopyFromRecordset cnn.Execute(SQL)
- Else
- SQL = "select * from [Excel 8.0;hdr=no;Database=" & File & ";].[清算表$b3:b]"
- Cells(4, m + 1).CopyFromRecordset cnn.Execute(SQL)
- End If
- Cells(3, m + 1) = Replace(File.Name, ".xls", "")
- End If
- Next
- Set Fso = Nothing
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|