|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 本月数()
Dim Fso As Object, File As Object, cnn As Object, SQL$, n&, arr, brr(17, 1), i&
Set Fso = CreateObject("Scripting.FileSystemObject")
Set cnn = CreateObject("adodb.connection")
For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
If File.Name Like "*.xls" And File.Name <> ThisWorkbook.Name Then
n = n + 1
If n = 1 Then cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & File
SQL = "select * from [Excel 12.0;hdr=no;Database=" & File & ";].[本月数$C7:D24]"
arr = cnn.Execute(SQL).GetRows
For i = 0 To 17
brr(i, 0) = brr(i, 0) + arr(0, i)
brr(i, 1) = brr(i, 1) + arr(1, i)
Next
End If
Next
Range("C7:D24") = brr
cnn.Close
Set cnn = Nothing
Set Fso = Nothing
End Sub
Sub 上月数()
Dim Fso As Object, File As Object, cnn As Object, SQL$, n&, arr, brr(17, 1), i&
Set Fso = CreateObject("Scripting.FileSystemObject")
Set cnn = CreateObject("adodb.connection")
For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
If File.Name Like "*.xls" And File.Name <> ThisWorkbook.Name Then
n = n + 1
If n = 1 Then cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & File
SQL = "select * from [Excel 12.0;hdr=no;Database=" & File & ";].[本月数$F7:G24]"
arr = cnn.Execute(SQL).GetRows
For i = 0 To 17
brr(i, 0) = brr(i, 0) + arr(0, i)
brr(i, 1) = brr(i, 1) + arr(1, i)
Next
End If
Next
Range("f7:g24") = brr
cnn.Close
Set cnn = Nothing
Set Fso = Nothing
End Sub
|
|