|
哪位老师能帮忙指点一下,改改以下代码,达到我附件汇总表的要求。下面代码是提取在同一文件夹下多个excel的数据,我需要的是在不同的文件夹下提取excel的数据,且希望是按文件夹的顺序依次提取(同一文件夹下有可能需提取几个不同的excel文件,但格式都是一样的),汇总表最后一行希望能做个汇总数。谢谢!
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set cnn = CreateObject("adodb.connection")
[a7:e1000].ClearContents
h = 7
f = Dir(ThisWorkbook.Path & "\*.xls")
Do While f > " "
If f <> ThisWorkbook.Name Then
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=no';data source=" & ThisWorkbook.Path & "\" & 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
h = h + 1
cnn.Close
End If
f = Dir
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub |
|