|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码如下。。。
Sub test() '选择打印机,然后打印的方案
Dim wb As Workbook, sht As Worksheet, sh As Worksheet, arr(), brr
Set wb = ThisWorkbook
Set sht = wb.Sheets("模板")
Set sh = wb.Sheets("数据")
brr = sh.Range("c5:l" & sh.Cells(Rows.Count, 3).End(3).Row)
ReDim arr(1 To 10000, 1 To 8)
For i = 1 To UBound(brr)
If brr(i, 2) = sht.[b2] And brr(i, 1) = sht.[i2] Then
n = n + 1
For j = 4 To UBound(brr, 2)
arr(n, j - 3) = brr(i, j)
Next
arr(n, 8) = brr(i, 3)
End If
Next
Application.Dialogs(9).Show
sht.PageSetup.PrintArea = "A1:I37"
If n / 25 > 1 Then
For i = 1 To Int(n / 25) + 1
m = 0
sht.[b4:i28].ClearContents
If n > i * 25 Then x = i * 25 Else x = n
For j = (i - 1) * 25 + 1 To x
m = m + 1
For k = 1 To 8
sht.Cells(m + 3, k + 1) = arr(j, k)
Next
Next
sht.PrintOut
Next
Else
sht.PrintOut
End If
Beep
End Sub
Sub test1() '输出PDF的方案
Dim wb As Workbook, sht As Worksheet, sh As Worksheet, arr(), brr
Set wb = ThisWorkbook
Set sht = wb.Sheets("模板")
Set sh = wb.Sheets("数据")
brr = sh.Range("c5:l" & sh.Cells(Rows.Count, 3).End(3).Row)
ReDim arr(1 To 10000, 1 To 8)
For i = 1 To UBound(brr)
If brr(i, 2) = sht.[b2] And brr(i, 1) = sht.[i2] Then
n = n + 1
For j = 4 To UBound(brr, 2)
arr(n, j - 3) = brr(i, j)
Next
arr(n, 8) = brr(i, 3)
End If
Next
If n / 25 > 1 Then
For i = 1 To Int(n / 25) + 1
m = 0
sht.[b4:i28].ClearContents
If n > i * 25 Then x = i * 25 Else x = n
For j = (i - 1) * 25 + 1 To x
m = m + 1
For k = 1 To 8
sht.Cells(m + 3, k + 1) = arr(j, k)
Next
Next
sht.ExportAsFixedFormat xlTypePDF, wb.Path & "\输出页" & i & ".pdf"
Next
Else
sht.ExportAsFixedFormat xlTypePDF, wb.Path & "\输出页" & i & ".pdf"
End If
Beep
End Sub
|
|