|
ADO法速度较快,但仅复制数值,不保留格式,请参考:- Sub ADO法()
- Dim cnn As Object, SQL$, f, l&
- f = Application.GetOpenFilename(fileFilter:="Excel文件(*.xlsx),*.xlsx", Title:="选择Excel文件", MultiSelect:=True)
- If TypeName(f) = "Boolean" Then Exit Sub
- Application.ScreenUpdating = False
- Set sh = ActiveSheet
- sh.UsedRange.Offset(2).ClearContents
- For l = 1 To UBound(f)
- If l = 1 Then
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & f(l)
- SQL = "select * from [sheet1$A2:L]"
- Range("a3").CopyFromRecordset cnn.Execute(SQL)
- Else
- SQL = "select * from [Excel 12.0;Database=" & f(l) & ";].[sheet1$A2:L]"
- Range("a" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)
- End If
- Next
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- MsgBox "ok"
- End Sub
复制代码 |
|