- Sub test()
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets("数据表").UsedRange
- For i = 3 To UBound(arr)
- d(arr(i, 1)) = d(arr(i, 1)) & "," & i
- Next
- With Sheets("证件打印")
- For Each k In d.keys
- .Range("g3:ab17").ClearContents
- n = 10
- a = Split(d(k), ",")
- For i = 1 To UBound(a)
- r = a(i)
- If arr(r, 11) = "户主" Then
- .[k3] = arr(r, 7)
- .[k4] = arr(r, 8)
- .[k5] = " " & Mid(k, 7, 4) & " " & Val(Mid(k, 11, 2)) '前边的空格多少自己增减调节
- .[k6] = arr(r, 16)
- For j = 1 To Len(k)
- .Cells(7, 10 + j) = Mid(k, j, 1)
- Next
- .[k8] = arr(r, 4) & arr(r, 5) & arr(r, 17)
- .[k9] = arr(r, 18)
- .[z9] = arr(r, 12)
- .[M16] = Format(arr(r, 23), " yyyy m d") 'yyyy前空格请自行调节
- For j = 1 To Len(arr(r, 24))
- .Cells(17, j + 12) = Mid(arr(r, 24), j, 1)
- Next
- Else
- n = n + 1
- .Cells(n, 9) = arr(r, 7)
- .Cells(n, 13) = arr(r, 11)
- .Cells(n, 17) = arr(r, 8)
- .Cells(n, 19) = Mid(arr(r, 10), 7, 4) & "." & Val(Mid(arr(r, 10), 11, 2))
- .Cells(n, 22) = arr(r, 12)
- .Cells(n, 26) = arr(r, 38)
- End If
- Next
- MsgBox "请放置打印纸。"
- .PrintOut
- Next
- End With
- End Sub
复制代码 以上代码为证件套打,有大神可以帮忙完善一下吗?
能否加入容错机制:当前证件打印完成后,如果打印正确,则询问打印下一个证件或者结束打印;如果打印不正确,则重新打印或结束打印。
|