|
请参考:
- Sub ADO法()
- Dim cnn As Object, SQL$, MyFile$, m%
- Application.ScreenUpdating = False
- ActiveSheet.UsedRange.Offset(1).ClearContents
- Set cnn = CreateObject("adodb.connection")
- MyFile = Dir(ThisWorkbook.Path & "\*.xls")
- While MyFile <> ""
- If MyFile <> ThisWorkbook.Name Then
- m = m + 1
- If m = 1 Then
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties='excel 12.0;hdr=no';Data Source=" & ThisWorkbook.Path & "" & MyFile
- SQL = "select * from [考勤$B3:M]"
- Range("A2").CopyFromRecordset cnn.Execute(SQL)
- Else
- SQL = "select * from [Excel 12.0;hdr=no;Database=" & ThisWorkbook.Path & "" & MyFile & "].[考勤$B3:M]"
- Range("A" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)
- End If
- End If
- MyFile = Dir()
- Wend
- cnn.Close
- Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|