|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参考,先完成第一步
- Sub ADO纵向合并多薄首表多区域()
- Dim Fso As Object, File As Object, cnn As Object, SQL$, m&
- Application.ScreenUpdating = False
- Set Fso = CreateObject("Scripting.FileSystemObject")
- ActiveSheet.UsedRange.Clear
- For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
- If File.Name Like "*.xlsx" And File.Name <> ThisWorkbook.Name Then
- m = m + 1
- If m = 1 Then
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no';Data Source=" & File
- SQL = "select F1,F2,F3 from [A2:E] where f2 is not null"
- [a1].CopyFromRecordset cnn.Execute(SQL)
- SQL = "select F1,F4,F5 from [A2:E] where f4 is not null"
- Range("a65536").End(3).Offset(1, 0).CopyFromRecordset cnn.Execute(SQL)
- Else
- SQL = "select F1,F2,F3 from [Excel 12.0;hdr=no;Database=" & File & ";].[A2:E] where f2 is not null"
- Range("a65536").End(3).Offset(1, 0).CopyFromRecordset cnn.Execute(SQL)
- SQL = "select F1,F4,F5 from [Excel 12.0;hdr=no;Database=" & File & ";].[A2:E] where f4 is not null"
- Range("a65536").End(3).Offset(1, 0).CopyFromRecordset cnn.Execute(SQL)
- End If
- End If
- Next
- Set Fso = Nothing
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
- 'http://club.excelhome.net/thread-1145518-1-1.html
复制代码 |
|