|
提速一倍多一点,不是很理想:
- Sub Macro1()
- t = Timer
- Dim Fso As Object, Folder As Object, arr$(), m&, i&, p$
- Application.ScreenUpdating = False
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Folder = Fso.GetFolder(ThisWorkbook.Path)
- Call GetFiles(Folder, arr, m)
- Set mycnn = CreateObject("adodb.connection")
- mycnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=excel 12.0;Data Source=" & arr(1)
- ActiveSheet.UsedRange.Offset(1).ClearContents
- For i = 1 To m
- mySQL = "select * from [Excel 12.0;Database=" & arr(i) & "].[数据库$]"
- Range("A65536").End(xlUp).Offset(1, 0).CopyFromRecordset mycnn.Execute(mySQL)
- Next
- Application.ScreenUpdating = True
- Set Folder = Nothing
- Set Fso = Nothing
- MsgBox Timer - t
- End Sub
- Sub GetFiles(ByVal Folder As Object, arr$(), m&)
- Dim SubFolder As Object
- Dim File As Object
- If Folder.Path <> ThisWorkbook.Path Then
- For Each File In Folder.Files
- If File.Name Like "*.xls*" Then
- m = m + 1
- ReDim Preserve arr(1 To m)
- arr(m) = File
- End If
- Next
- End If
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder, arr, m)
- Next
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|