|
- Sub cax()
- Dim Conn, SQL$, myPath$, Rst, sRan As Range, i&
- Set sRan = Range("A2")
- Range("a2:g1000").ClearContents
- myPath = ThisWorkbook.Path & ""
- Set Conn = CreateObject("adodb.connection")
- Set Rst = CreateObject("adodb.recordset")
- Conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & _
- "extended properties=excel 8.0;" & _
- "data source=" & myPath & [k1].Value & ".xls"
- Conn.Open
- If Conn.State = 1 Then
- SQL = "select 考号,姓名,数学 from [年级$a2:g]"
- Rst.Open SQL, Conn, 1, 3
- For i = 0 To Rst.Fields.Count - 1
- sRan.Offset(0, i).Value = Rst.Fields(i).Name
- Next
- sRan.Offset(1, 0).CopyFromRecordset Conn.Execute(SQL)
- Conn.Close
- End If
- Set Conn = Nothing
- End Sub
复制代码 |
|