|
- Sub test()
- Dim d As New Dictionary
- Dim cnn As New ADODB.Connection
- Dim rs As New ADODB.Recordset
- Dim ws As Worksheet
- Dim sql As String
- Dim mybook As String
- Dim mysheet As String
- Dim wbname As String
- Dim i As Integer
-
- Application.DisplayAlerts = False
-
- mybook = ThisWorkbook.FullName
- wbname = Dir(ThisWorkbook.Path & "\*.xls")
-
- Do While wbname <> ""
- If wbname <> "汇总.xls" Then
- d(wbname) = ""
- End If
- wbname = Dir()
- Loop
-
- With cnn
- .Provider = "microsoft.jet.oledb.4.0"
- .ConnectionString = "extended properties=""excel 8.0;HDR=YES;"";data source=" & mybook
- .Open
- End With
-
- kk = d.Keys
- For Each ws In Worksheets
- sql = ""
- For i = 0 To UBound(kk)
- sql = sql & " union all select * from [Excel 8.0;database=" & ThisWorkbook.Path & "" & kk(i) & "].[" & ws.Name & "$a3:h]"
- Next
- sql = Mid(sql, 11)
- sql = "select 姓名,sum(出勤天数),sum(基本工资),sum(绩效工资),sum(各项保险),sum(话费补助),sum(出差补助),sum(应发工资) from (" & sql & ") where not isnull(姓名) and 姓名<>'合计' group by 姓名"
- rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
- With ws
- .UsedRange.Offset(3, 0).ClearContents
- .Range("a4").CopyFromRecordset rs
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Cells(r + 1, 1) = "合计"
- .Cells(r + 1, 2).Resize(1, 7).FormulaR1C1 = "=SUM(R[" & 3 - r & "]C:R[-1]C)"
- .Range("a3:h" & r + 1).Borders.LineStyle = xlContinuous
- End With
- rs.Close
- Next
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- Application.DisplayAlerts = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|