|
|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
linyh1742595842 发表于 2015-5-6 16:38 
老师!可否增加(第 x 页/共 x 页)的功能? 再加一个条件,打印时间。
几经修改,本代码通过inputbox选择底端需固定的区域,不再受工作表行高影响。
供参考,请测试
- Sub test()
- Dim rng As Range, Rs&, r&, m&, n&, i&, T$
- With ActiveSheet
- Rs = .[A65536].End(xlUp).Row
- n = .HPageBreaks.Count
- If n = 0 Then
- .PrintOut
- ElseIf .HPageBreaks(1).Location.Row > Rs Then
- .PrintOut
- Else
- T = Now
- Set rng = Application.InputBox(Prompt:="请选择底端标题行", Title:="底端标题", Type:=8)
- If Not rng Is Nothing Then
- r = rng.Row
- If r > Rs Then Exit Sub
- Application.ScreenUpdating = False
- m = n * rng.Rows.Count
- .Rows(r).Resize(m).Insert
- n = .HPageBreaks.Count
- If .HPageBreaks(n).Location.Row < .[A65536].End(xlUp).Row Then n = n + 1
- .Rows(r).Resize(m).Delete
- For i = 1 To n
- .Rows("1:" & r - 1).Hidden = True
- Do
- s = s + 1
- If s > r Then Exit Do
- .Rows(s).Hidden = False
- If .HPageBreaks.Count > 0 Then
- If .HPageBreaks(1).Location.Row <= Rs Then
- Do
- .Rows(s).Hidden = True
- s = s - 1
- Loop Until .HPageBreaks.Count = 0
- End If
- Exit Do
- End If
- Loop
- .PageSetup.CenterFooter = "第" & i & "页,共" & n & "页"
- .PageSetup.RightHeader = T
- .PrintOut
- Next i
- .Rows("1:" & r - 1).Hidden = False
- .PageSetup.CenterFooter = ""
- .PageSetup.RightHeader = ""
- Set rng = Nothing
- Application.ScreenUpdating = True
- End If
- End If
- End With
- End Sub
复制代码
在每页后打印一个固定的表格.rar
(23.66 KB, 下载次数: 63)
|
评分
-
1
查看全部评分
-
|