|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub limonet()
Dim Cn As Object, Yin$, Kui$
Set Cn = CreateObject("Adodb.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Path$ = ThisWorkbook.Path & "\"
Filename$ = Dir(Path & "*.xls?")
Do While Filename <> ""
If Filename <> "汇总工作簿.xlsm" Then
If Filename Like "*盈*" Then
Yin = Yin & " Union All Select * From [Excel 12.0;DataBase=" & Path & Filename & "].[" & Split(Filename, ".xls")(0) & "$A3:R] Where 出库_入库='金额列的合计数'"
Else
Kui = Kui & " Union All Select * From [Excel 12.0;DataBase=" & Path & Filename & "].[" & Split(Filename, ".xls")(0) & "$A3:R] Where 出库_入库='金额列的合计数'"
End If
End If
Filename = Dir
Loop
Worksheets("盈").Range("A4").CopyFromRecordset Cn.Execute(Mid(Yin, 12))
Worksheets("亏").Range("A4").CopyFromRecordset Cn.Execute(Mid(Kui, 12))
End Sub
|
|