|
请测试一下!
3分半,生成200份索赔单,个人觉得不太满意
- Sub autoT()
- Application.ScreenUpdating = False
- Dim arr, brr, Mxi, Tongx, t, i&, j%, k%, a, b, facN
- Dim wb As Workbook, wk As Workbook
- Dim sh As Worksheet, ipath
- t = Timer
- ipath = ThisWorkbook.Path & "\索赔单"
- Set Mxi = CreateObject("scripting.dictionary")
- Set Tongx = CreateObject("scripting.dictionary")
- arr = Array("J4", "D5", "C17", "A17", "c4", "D8", "J8", "H10", "D10", "J10", "I21")
- brr = Array("I6", "J6", "I7")
- '清空标准表单
- For i = 0 To UBound(arr)
- Range(arr(i)) = ""
- Next
- For i = 0 To UBound(brr)
- Range(brr(i)) = ""
- Next
- Set wb = Workbooks.Open(ThisWorkbook.Path & "\索赔明细.xlsx")
- ' wb.Sheet1.Activate
- With ActiveSheet
- a = .Range("A2:I" & .[a1].End(4).Row)
- For i = 1 To UBound(a)
- For j = 2 To 9
- Mxi(a(i, 1)) = Mxi(a(i, 1)) & a(i, j) & vbTab
- Next
- Next
- End With
- Erase a: wb.Close False: i = 1
- Set wb = Nothing
- '
- ' '按Mxi序号批量建立sheets
- ' For i = 1 To Mxi.Count
- ' If TypeName(Application.Evaluate("(" & i & ")!A1")) = "Error" Then
- ' Sheets("标准").Copy after:=Worksheets(Worksheets.Count)
- ' With ActiveSheet
- ' .Name = "(" & i & ")"
- ' End With
- ' End If
- ' Next
-
- Set wb = Workbooks.Open(ThisWorkbook.Path & "\标准通讯录.xls")
- With ActiveSheet
- a = .Range("D2:G" & .[d2].End(4).Row)
- For i = 1 To UBound(a)
- Tongx(a(i, 1)) = a(i, 2) & vbTab & a(i, 3) & vbTab & a(i, 4)
- Next
- End With
- Erase a: wb.Close False
- Set wb = Nothing
-
- For i = 1 To Mxi.Count
- a = Split(Mxi(i), vbTab)
- With ActiveSheet
- For k = 0 To UBound(arr) Step 1
- If k <= 7 Then
- .Range(arr(k)) = a(k)
- End If
- If k = 8 Then .Range(arr(k)) = a(5)
- If k = 9 Then .Range(arr(k)) = a(6)
- If k = 10 Then .Range(arr(k)) = a(2)
- Next
- formN = Right(a(4), 6)
- Erase a
- facN = .Range(arr(1))
- b = Split(Tongx(facN), vbTab)
- For j = 0 To UBound(brr)
- .Range(brr(j)) = "" & b(j)
- Next
- Erase b
- fname = formN & facN
- Set wk = Workbooks.Add
- .Copy before:=wk.Worksheets("sheet1")
- For Each sh In wk.Worksheets
- If sh.Name Like "*Sheet*" Then
- Application.DisplayAlerts = False
- sh.Delete
- Application.DisplayAlerts = True
- End If
- Next sh
- wk.SaveAs ipath & fname & ".xls"
- wk.Close
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "成功生成 " & Mxi.Count & " 份索赔单,耗时 " & Format(Timer - t, "0.000") & " 秒!"
- End Sub
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|