|
- Sub Opiona()
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- t = Timer '//开始时间
- PathG = ThisWorkbook.Path & "\分表"
- Set FSO = CreateObject("Scripting.FileSystemObject")
- If FSO.FolderExists(PathG) = True Then
- FSO.GetFolder(PathG).Delete '//删除文件夹
- End If
- Delay 1 '延迟3秒
- MkDir PathG '//创建文件夹
-
-
- Set SH1 = Sheets("Sheet1")
- Str_coon = "HDR=NO';Data Source =" & ThisWorkbook.FullName '//OFFICE2003,2007 通用
- StrSQL = "SELECT DISTINCT F2 FROM [" & SH1.Name & "$A:C] WHERE LEN(F2)>0"
-
- ARX = GET_SQL_To_Arr(StrSQL, Str_coon, False)
- For X = 0 To UBound(ARX, 1)
- StrSQL = "SELECT F1,F2,F3 FROM [" & SH1.Name & "$] WHERE F2='" & ARX(X, 0) & "'"
- SQLARX = GET_SQL_To_Arr(StrSQL, Str_coon, False)
-
- INTG = 1 '记录是此编码的第几个表
- For I = 0 To UBound(SQLARX, 1) Step 500
- Set WB = Workbooks.Add
- Set SHW = WB.Worksheets(1)
- ReDim ARXX(0 To 499, 0 To 2)
-
- MAXROW = 0
- For Y = 0 To 499
- MAXROW = MAXROW + 1 '//记录本表有多少行数据
- If I + Y <= UBound(SQLARX, 1) Then
- For m = 0 To 2
- ARXX(Y, m) = SQLARX(I + Y, m)
- Next m
- Else
- Exit For
- End If
- Next Y
- SHW.Range("A1").Resize(UBound(ARXX, 1) + 1, UBound(ARXX, 2) + 1) = ARXX
- WB.SaveAs PathG & "\自定义名称-" & ARX(X, 0) & "-" & Format(INTG, "00") & " " & MAXROW & ".XLSX"
- WB.Close True
- INTG = INTG + 1
- Next I
- Next X
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
|