|
Sub ADO_一行一薄()
Dim sh As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim cnn, rs, sql$
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.Recordset")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.Path & "\代维电池放电测试站点汇总.xlsx"
sql = "select * from [sheet1$B1:L] where 站名 is not null"
rs.Open sql, cnn, 1, 1
Do While Not rs.EOF
Workbooks.Add
ThisWorkbook.Sheets(1).Rows("1:50").Copy [A1]
ThisWorkbook.Sheets(1).Columns("A:L").Copy [A1]
[A2] = rs.Fields(1)
[E2] = rs.Fields(0)
[I2] = rs.Fields(2)
[N2] = rs.Fields(3)
[A3] = rs.Fields(4)
[J3] = rs.Fields(5)
[A4] = rs.Fields(6)
[F4] = rs.Fields(7)
[K4] = rs.Fields(8)
[R4] = rs.Fields(9)
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & rs.Fields(0)
ActiveWorkbook.Close
rs.MoveNext
Loop
rs.Close
cnn.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
|
|