|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- 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 & "].[" & s & "] FROM [" & ActiveSheet.Name & "$] WHERE 负责区域='" & s & "'"
- rs.MoveNext
- Wend
- rs.Close
- Set rs = Nothing
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|