|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test0() '慢慢等,不会慢
- Dim Conn As Object, rs As Object, p As String, f As String, s As String
- p = ThisWorkbook.Path & "\分簿"
- If Dir(p, vbDirectory) = "" Then MkDir p
- Set Conn = CreateObject("ADODB.Connection")
- Set rs = CreateObject("ADODB.Recordset")
- Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0 XML;Data Source=" & ThisWorkbook.FullName
- s = "SELECT DISTINCT 名字 FROM [" & ActiveSheet.Name & "$] WHERE LEN(名字)"
- rs.Open s, Conn, 1, 3
- While Not rs.EOF
- s = rs.Fields(0).Value
- f = p & Application.PathSeparator & s & ".xlsx"
- If Dir(f) <> "" Then Kill f
- Conn.Execute "SELECT * INTO [" & f & "].[Sheet1] FROM [" & ActiveSheet.Name & "$] WHERE 名字='" & s & "'"
- rs.MoveNext
- Wend
- rs.Close
- Set rs = Nothing
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|