|
Sub limonet()
Dim Cn As Object, StrSQL$, Arr As Variant, i%, CS$
Set Cn = CreateObject("Adodb.Connection")
CS = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0 xml;Data Source="
Cn.Open CS & ThisWorkbook.FullName
Arr = Cn.Execute("Select Distinct 学校&'-'&年级&'-'&班级 From [成绩$] Where 学校<>''").GetRows
For i = 0 To UBound(Arr, 2)
Cn.Close
Cn.Open CS & ThisWorkbook.Path & "\" & Arr(0, i) & ".xlsx"
StrSQL = "Select * Into Sheet1 From [Excel 12.0;DataBase=" & ThisWorkbook.FullName & "].[成绩$] Where 学校&'-'&年级&'-'&班级='" & Arr(0, i) & "'"
Cn.Execute (StrSQL)
Next i
End Sub |
|