|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
拆分到工作簿
Option Explicit
Sub a()
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$A1:f] 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:g").Copy [a1]
[a7] = rs.Fields(0)
[d7] = rs.Fields(1)
[a9] = rs.Fields(2)
[c9] = rs.Fields(3)
[c16] = rs.Fields(4)
[d16] = rs.Fields(5)
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
|
评分
-
1
查看全部评分
-
|