|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 打印()
- Dim c As Range, s$, r%, n%, x%, y%, a%, b%
- r = Range("a65536").End(3).Row
- s = "本页小计"
- On Error Resume Next
- n = Application.Match(s, ActiveSheet.Range("A1:A" & r), 0)
- If Err.Number = 0 Then
- x = n - 4 '每页正表行数(不包括表头表尾)
- y = WorksheetFunction.RoundUp((r - 6) / x, 0) '共有几页
- For i = 1 To y '循环
- If y = 1 Then '如果只有一页
- With ActiveSheet.PageSetup
- .Zoom = False '不设置页面缩放固定比例择
- .FitToPagesWide = 1 '页面缩放,调整为一页高
- .FitToPagesTall = 1 '页面缩放,调整为一页宽
- .BlackAndWhite = True '单色打印
- .Orientation = xlLandscape '横向打印
- Range("a1:U" & r).PrintPreview '打印预览
- End With
- Else
- If i = 1 Then
- a = x + 5
- Rows(a & ":" & r - 1).EntireRow.Hidden = True
- End If
- If i > 1 And i < y Then
- Rows(5 & ":" & (i - 1) * x + 4).EntireRow.Hidden = True
- Rows(i * x + 5 & ":" & r - 1).EntireRow.Hidden = True
- End If
- If i = y Then
- b = (i - 1) * x + 4
- Rows("5:" & b).EntireRow.Hidden = True
- End If
- End If
- With ActiveSheet.PageSetup
- .Zoom = False '不设置页面缩放固定比例择
- .FitToPagesWide = 1 '页面缩放,调整为一页高
- .FitToPagesTall = 1 '页面缩放,调整为一页宽
- .BlackAndWhite = True '单色打印
- .Orientation = xlLandscape '横向打印
- Range("a1:U" & r).PrintPreview '打印预览
- End With
- Rows(1 & ":" & r).EntireRow.Hidden = False
- Next
- Else
- MsgBox "没有查到"
- End If
- End Sub
复制代码 |
|