|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- 'http://club.excelhome.net/thread-1341555-1-1.html
- Sub test()
- Dim cnn As Object, SQL As String, MyPath$, MyFile$, n As Long
- ' Cells.Clear
- Set cnn = CreateObject("ADODB.Connection")
- MyPath = ThisWorkbook.Path & ""
- MyFile = Dir(MyPath & "*.xlsx")
- Do While MyFile <> ""
- If MyFile <> ThisWorkbook.Name Then
- n = n + 1
- If n = 1 Then
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no';Data Source=" & MyPath & MyFile
- SQL = "SELECT * FROM [设计评审表$A17:BO17] WHERE F1 IS NOT NULL"
- Else
- SQL = SQL & " UNION ALL SELECT * FROM [Excel 12.0;HDR=NO;Database=" & MyPath & MyFile & "].[设计评审表$A17:BO17] "
- End If
- End If
- MyFile = Dir()
- Loop
- Range("A4").CopyFromRecordset cnn.Execute(SQL)
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|