|
一个部门一个PDF文件- Sub ykcbf2() '//2024.7.25
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set ws = ThisWorkbook
- p = ws.Path & ""
- Set sh = ws.Sheets("模板")
- With sh
- Set Rng = .UsedRange.Find("申请理由")
- c = Rng.Column: r1 = Rng.Row
- For j = 2 To c
- s = Trim(.Cells(r1, j).Value)
- d1(s) = j
- Next
- End With
- ReDim brr(1 To 1000, 1 To c)
- With ws.Sheets("数据")
- Set Rng = .UsedRange.Find("金额")
- c = Rng.Column: r1 = Rng.Row
- r = .Cells(Rows.Count, 2).End(3).Row
- arr = .[a1].Resize(r, c)
- For i = r1 + 1 To UBound(arr)
- s = arr(i, 4) & "|" & arr(i, 3)
- If Not d.exists(s) Then Set d(s) = CreateObject("Scripting.Dictionary")
- d(s)(i) = i
- Next
- End With
- rr = 25 '//模板内容行数
- On Error Resume Next
- For Each k In d.keys
- bm = Split(k, "|")(0)
- rq = Split(k, "|")(1)
- m = 0: y = 0
- For Each kk In d(k).keys
- m = m + 1
- brr(m, 1) = m
- For j = 3 To UBound(arr, 2)
- s = arr(r1, j)
- brr(m, d1(s)) = arr(kk, j)
- Next
- Next
- k = m \ rr + 1 '//分页计数
- mm = 45
- sh.Copy
- Set wb = ActiveWorkbook
- For x = 1 To k
- r1 = (x - 1) * rr + 1
- If x = k Then r2 = m Else r2 = rr * x
- ReDim zrr(1 To rr, 1 To 9)
- n = 0
- For i = r1 To r2
- y = y + 1 '//总序号
- n = n + 1 '//分表计数
- zrr(n, 1) = Format(y, "00")
- For j = 2 To UBound(brr, 2)
- zrr(n, j) = brr(i, j)
- Next
- Next
- With wb.Sheets(1)
- If x = 1 Then
- .[b2] = bm: .[i2] = rq
- .[a4].Resize(n, 9) = zrr
- Else
- sh.Rows("1:37").Copy .Cells(1 + (x - 1) * mm, 1)
- .Cells(2 + (x - 1) * mm, 2) = bm: .Cells(2 + (x - 1) * mm, "i") = rq
- .Cells(4 + (x - 1) * mm, 1).Resize(n, 9) = zrr
- End If
- End With
- Next
- r = mm * k
- fn = Format(CDate(rq), "yyyymd")
- wb.Sheets(1).Range("A1:i" & r).ExportAsFixedFormat xlTypePDF, p & bm & "-" & fn & ".pdf"
- wb.Close 0
- Next
- Application.ScreenUpdating = False
- MsgBox "OK!"
- End Sub
复制代码
|
|