|
ADO法速度较快,请参考:
Sub ADO法()
Dim cnn As Object, rs As Object, i&, SQL$, s$
Application.ScreenUpdating = False
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider = Microsoft.ace.Oledb.12.0;Extended Properties =Excel 12.0;Data Source =" & ThisWorkbook.Path & "\明细表.xlsx"
Set rs = cnn.OpenSchema(20)
ActiveSheet.UsedRange.Offset(, 2).ClearContents
i = 2
Do Until rs.EOF
If rs.Fields("TABLE_TYPE") = "TABLE" Then
s = Replace(rs("TABLE_NAME").Value, "'", "")
If Right(s, 1) = "$" Then
i = i + 1
SQL = "select 合计 from [" & s & "]"
Cells(1, i) = Replace(s, "$", "")
Cells(2, i).CopyFromRecordset cnn.Execute(SQL)
End If
End If
rs.MoveNext
Loop
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|