|
楼主 |
发表于 2013-10-12 23:12
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 hzruziniu 于 2013-10-12 23:36 编辑
qdming 发表于 2013-10-12 11:30
楼主,凭证打印表里附件张数不显示
在连续打印和逐张打印的代码中分别加入红色的二句代码就行了,
注意:原始凭证张数分别在凭证号码的第一行输入.
Sub 连续打印()
Dim arr, ary(), brr, crr, drr, err, frr, x As WorksheetFunction, i As Integer, j As Integer
Dim a1 As Integer, a2 As Integer, n As Integer, n2 As Integer, m As Integer
Set x = WorksheetFunction
With Sheets("分录")
arr = .Range("d1:f" & .Range("d65536").End(3).Row + 1) '源表的日期加凭证编号起始区域为arr
ReDim ary(1 To 1)
ary(1) = 4
m = 1
For i = 5 To UBound(arr) '源表的行上下限
If arr(i, 1) & "/" & arr(i, 3) <> arr(i - 1, 1) & "/" & arr(i - 1, 3) Then
m = m + 1
ReDim Preserve ary(1 To m)
ary(m) = i
End If
Next
'-----------------------------------------------------------------------------------------------
a1 = Range("am1").Value '打印表开始号
a2 = Range("an1").Value '打印表结束号
a = [al1] '打印表的月份
For k = a1 To a2
t2 = a & "/" & k '打印表的"月/凭证号"定义为t2
For i = 4 To UBound(arr)
If arr(i, 1) & "/" & arr(i, 3) = t2 Then
r = i
Exit For
End If
Next
i = 0
If r > 0 Then
For l = 1 To m
If r = ary(l) Then
i = l
Exit For
End If
Next
End If
'----------------------------------------------------------------------------------------------------------
If i = 0 Then GoTo 100
n = x.RoundUp((ary(i + 1) - ary(i)) / 7, 0) '该凭证号一共有几张分页号
n2 = n * 7 - (ary(i + 1) - ary(i)) '最后一张凭证内有几行空行
temp = x.Sum(.Range(.Cells(ary(i), 15), .Cells(ary(i + 1) - 1, 15))) '贷方科目合计金额
'[c10] = N2RMB(temp)'人民币大写
[ai16] = x.Sum(.Range(.Cells(ary(i), 13), .Cells(ary(i + 1) - 1, 13))) '借方科目合计金额
[aj16] = temp
f = [am1]
For j = 1 To n
If j < n Then
'-------------------------------------------------------------
Range("z2") = Format(f, "000") & "号" & j & "/" & n
Range("f5") = Sheets("资料").Range("J5")
'Range("h5") = Range("al1")
Range("h5") = Sheets("分录").Cells(ary(i), 4)
Range("k5") = Sheets("分录").Cells(ary(i), 5)
Range("AA5") = Sheets("分录").Range("P" & ary(i))
brr = .Range("g" & (j - 1) * 7 + ary(i)).Resize(7)
crr = .Range("i" & (j - 1) * 7 + ary(i)).Resize(7)
drr = .Range("k" & (j - 1) * 7 + ary(i)).Resize(7)
err = .Range("m" & (j - 1) * 7 + ary(i)).Resize(7)
frr = .Range("o" & (j - 1) * 7 + ary(i)).Resize(7)
Range("B9:F15") = ""
Range("ai9:aj15") = ""
Range("b9:b15") = brr
Range("d9:d15") = crr
Range("f9:f15") = drr
Range("ai9:ai15") = err
Range("aj9:aj15") = frr
ActiveSheet.PrintPreview '打印预览
'ActiveSheet.PrintOut '直接打印
Else
Range("z2") = Format(f, "000") & "号" & j & "/" & n
Range("f5") = Sheets("资料").Range("J5")
'Range("h5") = Range("al1")
Range("h5") = Sheets("分录").Cells(ary(i), 4)
Range("k5") = Sheets("分录").Cells(ary(i), 5)
Range("AA5") = Sheets("分录").Range("P" & ary(i))
brr = .Range("g" & (j - 1) * 7 + ary(i)).Resize(7 - n2)
crr = .Range("i" & (j - 1) * 7 + ary(i)).Resize(7 - n2)
drr = .Range("k" & (j - 1) * 7 + ary(i)).Resize(7 - n2)
err = .Range("m" & (j - 1) * 7 + ary(i)).Resize(7 - n2)
frr = .Range("o" & (j - 1) * 7 + ary(i)).Resize(7 - n2)
Range("B9:F15") = ""
Range("ai9:aj15") = ""
amyr = 15 - n2
Range("b9:b" & amyr) = brr
Range("d9:d" & amyr) = crr
Range("f9:f" & amyr) = drr
Range("ai9:ai" & amyr) = err
Range("aj9:aj" & amyr) = frr
'Range("ak5") = amyr
'Range("ak3") = n2
Range("am1") = Range("am1") + 1
'Range("ak7") = m
ActiveSheet.PrintPreview '打印预览
'ActiveSheet.PrintOut '直接打印
End If
Next
100
Next
End With
End Sub
|
|