|
- Sub adodl()
- Dim StrSQL$, Cn As Object, x%
- Dim fileName, strTable, strPath
- Set Cn = CreateObject("ADODB.connection")
- Sheet16.Range("a:g").ClearContents
- Sheet16.Range("a1:f1") = Array("班级", "考号", "性别", "语文", "数学", "英语")
- strPath = ThisWorkbook.Path & ""
- fileName = Dir(strPath & "*.xlsx")
- x = 2
- Do While fileName <> ""
- If fileName <> "汇总.xlsm" Then
- Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no;imex=1';Data Source=" & strPath & fileName
- StrSQL = "select * from .[Sheet1$a2:f]"
- Sheet16.Range("a" & x).CopyFromRecordset Cn.Execute(StrSQL)
- x = Sheet16.Cells(Rows.Count, 1).End(xlUp).Row + 1
- Cn.Close
- End If
- fileName = Dir()
- Loop
- Set Cn = Nothing
- End Sub
复制代码 |
|