|
代码如下,,,
Sub test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
t = Timer
Dim wb As Workbook, sht As Worksheet, sh As Worksheet, sh1 As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("运单明细")
Set sh = wb.Sheets("打印模板")
Set sh1 = wb.Sheets("可批量打印的磅单")
arr = sht.[a1].CurrentRegion
Set rng = sh.[a1:g9]
For i = 2 To UBound(arr)
sh.[e2] = arr(i, 7)
sh.[b4] = arr(i, 3)
sh.[b5] = arr(i, 4)
sh.[b6] = arr(i, 5)
sh.[e4] = arr(i, 6)
sh.[g4] = arr(i, 1)
sh.[g7] = arr(i, 9)
sh.[b8] = arr(i, 10)
r = sh1.Cells(Rows.Count, 1).End(3).Row
r = IIf(r = 1, 1, r + 2)
rng.Copy sh1.Cells(r, 1)
Next
rng.Copy
sh1.Cells(r, 1).PasteSpecial 8 '调整列宽
Call PageBreaks
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "共耗时:" & Format(Timer - t, "0.0000") & " 秒!!!", 64
End Sub
Sub PageBreaks()
Dim rng_find As Range, rng As Range
With ThisWorkbook.Sheets("可批量打印的磅单")
.ResetAllPageBreaks
r = .Cells(.Rows.Count, 1).End(3).Row
With .PageSetup
.PrintArea = "a1:g" & r
n = 0
.Zoom = 100
' .CenterVertically = True
.CenterHorizontally = True
.Orientation = xlPortrait
End With
Windows(ThisWorkbook.Name).View = xlPageBreakPreview
x = .HPageBreaks.Count
For i = 11 To r Step 10
.HPageBreaks.Add .Rows(i)
Next
' .PageSetup.FitToPagesWide = 1
' .PrintPreview
End With
Windows(ThisWorkbook.Name).View = xlNormalView
End Sub
|
评分
-
1
查看全部评分
-
|