|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub Macro1()
- Dim cnn As Object, SQL$, p$, f$, m&
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xlsx")
- Set cnn = CreateObject("adodb.connection")
- Do While f <> ""
- m = m + 1
- If m = 1 Then
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='excel 12.0;hdr=no';Data Source=" & p & f
- SQL = "select * from [SURAT JALAN$r2:r2]"
- Else
- SQL = SQL & " union all select * from [Excel 12.0;hdr=no;Database=" & p & f & "].[SURAT JALAN$r2:r2]"
- End If
- f = Dir()
- Loop
- SQL = "select sum(f1) from (" & SQL & ")"
- [c4].CopyFromRecordset cnn.Execute(SQL)
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|