|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- 'Option Explicit
- Sub ado_一行一薄B()
- 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 = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=no';Data Source =" & ThisWorkbook.Path & "\数据库.xlsx"
- sql = "select * from [sheet1$A2:J11]"
- rs.Open sql, cnn, 1, 1
- On Error Resume Next
- Do While Not rs.EOF
- Workbooks.Add
- ThisWorkbook.Sheets(1).Rows("1:8").Copy [a1]
- ThisWorkbook.Sheets(1).Columns("A:G").Copy [a1]
- [B2] = rs.Fields(0)
- [B3] = rs.Fields(1)
- ' [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
复制代码 |
|