|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim cnn, mf$, mp$, wkt
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0';Data Source=" & ThisWorkbook.FullName
- mp = ThisWorkbook.Path
- mf = Dir(mp & "\*.xlsx")
- Do Until mf = ""
- If mf <> ThisWorkbook.Name Then
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With Workbooks.Open(mp & "" & mf)
- .Worksheets(1).UsedRange.Copy ThisWorkbook.Worksheets("Sheet2").[a1]
- cnn.Execute ("update [Sheet1$] a,[Sheet2$] b set b.[今日]=a.[今日],b.[累计]=a.[今日]+b.[累计] where a.姓名=b.姓名")
- ThisWorkbook.Worksheets("Sheet2").UsedRange.Copy .Worksheets(1).[a1]
- .Close 1
- End With
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End If
- mf = Dir
- Loop
- End Sub
复制代码
因新版本ADO限制了update的语句对链接表的更新,只能用这个笨办法了 |
|