|
- Sub huizong()
- Dim Fso As Object, File As Object
- Dim cnn As Object, rs As Object, sql$, brr(1 To 5, 1 To 13)
- Set cnn = CreateObject("adodb.connection")
- Set Fso = CreateObject("Scripting.FileSystemObject")
- ch = [b4]
- '============提取加油数据===============================
- For Each File In Fso.GetFolder(ThisWorkbook.Path & "\2014年车辆加油统计表").Files
- If File.Name Like "*.xls" Then
- n = n + 1
- yf = Val(Split(Split(File.Name, "年")(1), "月")(0))
- If n = 1 Then cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & File
- sql = "select f3, f4, f5, f6 from [Excel 8.0;hdr=no;imex=1;Database=" & File & ";].[Sheet1$a4:g] where f2= '" & ch & "'"
- Set rs = cnn.Execute(sql)
- arr = rs.GetRows
- For i = 0 To UBound(arr) Step 2
- If arr(i, 0) <> "Null" Then brr(1, yf) = arr(i, 0)
- Next
- For i = 1 To UBound(arr) Step 2
- If arr(i, 0) <> "Null" Then brr(2, yf) = arr(i, 0)
- Next
- End If
- Next
- '=================提取维修费用============================
- For Each File In Fso.GetFolder(ThisWorkbook.Path & "\2014年车辆日常维修统计表").Files
- If File.Name Like "*.xls" Then
- yf = Val(Split(Split(File.Name, "年")(1), "月")(0))
- sql = "select f15 from [Excel 8.0;hdr=no;imex=1;Database=" & File & ";].[Sheet1$a4:o] where f3= '" & ch & "'"
- Set rs = cnn.Execute(sql)
- arr = rs.GetRows
- brr(3, yf) = arr(0, 0)
- End If
- Next
- '=================提取轮胎费用============================
- For Each File In Fso.GetFolder(ThisWorkbook.Path & "\2014年车辆轮胎更换明细表").Files
- If File.Name Like "*.xls" Then
- yf = Val(Split(Split(File.Name, "年")(1), "月")(0))
- sql = "select sum(f8),sum(f12) from [Excel 8.0;hdr=no;imex=1;Database=" & File & ";].[Sheet1$a4:m] where f2= '" & ch & "'"
- Set rs = cnn.Execute(sql)
- arr = rs.GetRows
- brr(4, yf) = arr(0, 0)
- brr(5, yf) = arr(1, 0)
- End If
- Next
- [d4].Resize(5, 13).ClearContents
- [d4].Resize(UBound(brr), UBound(brr, 2)) = brr
- End Sub
复制代码 |
|