|
自动判断顶端标题行是根据表格中必须有数字所在的区域作为依据的,对话框可自由的输入(单行输入行数即可,多行2:4)- Sub 页面设置()
- Application.ScreenUpdating = 0
- If Application.WorksheetFunction.Count(Cells) = 0 Then GoTo 120
- On Error GoTo 110
- 标题行 = ActiveCell.SpecialCells(2, 1).CurrentRegion.Row: GoTo 120
- 110:
- 标题行 = ActiveCell.SpecialCells(xlCellTypeFormulas, 1).CurrentRegion.Row
- 120:
- 标题行 = Rows(IIf(标题行 = "", 1, 标题行)).Address
- Q = InputBox("每页 固定打印 标题行,自动判断为:" & 标题行, "请修改行数", 标题行)
- On Error Resume Next
- If Q = "" Then
- W = ""
- ElseIf Q = 标题行 Then
- W = Q
- Else
- W = Rows(Q).Address
- End If
-
- With ActiveSheet.PageSetup '本行开始是 工作表 打印 设置
- .PrintTitleRows = W '"$1:$1"
- .PrintTitleColumns = ""
- End With
- ActiveSheet.PageSetup.PrintArea = ""
-
- With ActiveSheet.PageSetup
- .CenterFooter = "共 &N 页,第 &P 页"
- .LeftMargin = Application.InchesToPoints(0.75) '左
- .RightMargin = Application.InchesToPoints(0.75) '右
- .TopMargin = Application.InchesToPoints(0.75) '顶边
- .BottomMargin = Application.InchesToPoints(0.39) '底边
- .HeaderMargin = Application.InchesToPoints(0.51) '页眉
- .FooterMargin = Application.InchesToPoints(0) '页脚
- .PrintGridlines = True '网格线
- .CenterHorizontally = True '水平居中
- .CenterVertically = False '垂直居中
- .PaperSize = xlPaperA4
- .Zoom = 100
- End With
- Application.ScreenUpdating = 1
- End Sub
复制代码 |
|