|
Sub test()
Dim cnn As Object
Dim rs As Object
Dim MySQL As String
Dim MyPath As String
Dim MyName As String
Dim ws As Worksheet
Dim wb As Workbook
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
MyPath = ThisWorkbook.Path & "\"
MyName = Dir(MyPath & "*.xls*")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
Do While MyName <> ""
If MyName <> "汇总.xls" Then
MySQL = "select * from [excel 12.0;database=" & MyPath & MyName & "].[中学$]"
rs.Open MySQL, cnn, 1, 3
With Sheets("中学")
r = .Cells(.Rows.Count, 1).End(3).Row
.Range("A" & r).CopyFromRecordset rs
End With
rs.Close
End If
MyName = Dir
Loop
End Sub
|
|