|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
请测试
Private Sub CommandButton1_Click()
Dim arr()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set cnn = CreateObject("adodb.connection")
[a7:e1000].ClearContents
MyPath = ThisWorkbook.Path & "\"
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
m = m + 1
ReDim Preserve arr(m)
arr(m) = MyPath & MyName & "\"
End If
End If
MyName = Dir
Loop
h = 7
For k = 1 To m
f = Dir(arr(k) & "*.xls")
Do While f > " "
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='excel 8.0;hdr=no';Data Source=" & arr(k) & f
Sql = "select * from [表一$e11:e11]"
Cells(h, 3).CopyFromRecordset cnn.Execute(Sql)
Sql = "select * from [表一$g11:g11]"
Cells(h, 4).CopyFromRecordset cnn.Execute(Sql)
Sql = "select * from [表一$h11:h11]"
Cells(h, 5).CopyFromRecordset cnn.Execute(Sql)
Cells(h, 2) = f
Cells(h, 1) = h - 6
h = h + 1
cnn.Close
f = Dir
Loop
Next
Cells(h, 2) = "合 计"
Cells(h, 3).Resize(, 3) = "=SUM(R[-" & h - 7 & "]C:R[-1]C)"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
[ 本帖最后由 zhaogang1960 于 2011-6-10 22:06 编辑 ] |
|