|
这个题目比较时间需要使用format函数,速度很慢,下面使用ADO+字典法速度很快:
Sub Macro1()
Dim Fso As Object, File As Object, cnn As Object, rs As Object, SQL$, m&, Ak&, ary, arr, brr(), i&, d As Object
Set d = CreateObject("scripting.dictionary")
Application.ScreenUpdating = False
ary = Range("A3:B" & Range("A65536").End(xlUp).Row)
Set cnn = CreateObject("adodb.connection")
Set Fso = CreateObject("Scripting.FileSystemObject")
ReDim brr(0 To UBound(ary), 1 To Fso.GetFolder(ThisWorkbook.Path).Files.Count - 1)
Columns("C:E").ClearContents
For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
If File.Name Like "*.xls" And File.Name <> ThisWorkbook.Name Then
m = m + 1
Ak = Replace(File.Name, ".xls", "")
If m = 1 Then cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=no';Data Source=" & File
SQL = "select * from [Excel 8.0;hdr=no;Database=" & File & ";].[" & Ak & "$b14:d]"
Set rs = cnn.Execute(SQL)
arr = rs.GetRows
For i = 0 To UBound(arr, 2)
d(arr(0, i) & "|" & arr(1, i)) = arr(2, i)
Next
For i = 1 To UBound(ary)
brr(i, m) = d(ary(i, 1) & "|" & Format(ary(i, 2), "h:mm:ss"))
Next
brr(0, m) = Replace(File.Name, ".xls", "")
End If
Next
[c2].Resize(UBound(ary) + 1, m) = brr
Set Fso = Nothing
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|