|
baiqitun23 发表于 2015-5-12 08:44
如附件,汇总表 A列 是excel文件名,B、C、D列分别是要提取的数据。
汇总表,与分表放在同一目录下
Sub hb()
Dim arr, brr(1 To 999, 1 To 4), mypath, myfile As String, i As Integer, m As Integer
Dim cnn, rs, sql As String
mypath = ThisWorkbook.Path & "\"
myfile = Dir(mypath & "*.xlsx")
Do While myfile <> ""
If myfile <> ThisWorkbook.Name Then
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=no';Data Source=" & mypath & myfile
sql = "select * from [三年二班$c20:e20]"
Set rs = cnn.Execute(sql)
arr = rs.getRows
m = m + 1
brr(m, 1) = Replace(myfile, ".xlsx", "")
brr(m, 2) = arr(0, 0)
brr(m, 3) = arr(1, 0)
brr(m, 4) = arr(2, 0)
End If
myfile = Dir
Loop
cnn.Close
Set cnn = Nothing
Set rs = Nothing
Sheet1.Activate
[a:d] = ""
[a1].Resize(m, 4) = brr
End Sub
|
评分
-
1
查看全部评分
-
|