首页 > 解决方案 > 打印时更新的 Excel 中的页码

问题描述

有没有办法将页码放在打印时更新的单元格中?

在此处输入图像描述

我将第 1-5 行设置为在每一页上重复。但是,我希望单元格 F1 中的页面值在打印时在每一页上更新。有没有办法做到这一点?

谢谢你。

标签: excelpage-numbering

解决方案


我认为,没有直接的方法可以在打印时增加单元格的价值。但是你可以使用VBA,如何使用VBA?你可以搜索一下。我的问题,打印区域在哪里?我假设打印区域来自同一张纸。

这里的代码:

Sub forprint()

    Dim nPrint As Variant
    Dim i, n As Long
    On Error Resume Next

    n = Range("F1").Value
    nPrint = Application.InputBox("Number of Copy", "Print")
    If TypeName(nPrint) = "Boolean" Then Exit Sub
        If (nPrint = "") Or (Not IsNumeric(nPrint)) Or (nPrint < 1) Then
            MsgBox "Enter number only & minimum 1 copy", vbExclamation, "Wrong character or value!"
        Else
            Application.ScreenUpdating = False
            For i = 1 To nPrint
                ActiveSheet.Range("F1").Value = n + nPrint
                Sheets("Sheet1").PrintOut '<< change Sheet1 to your sheet with the printarea
            Next
        Application.ScreenUpdating = True
    End If

End Sub

在 VBA 窗口中插入模块。单击插入>>模块,然后将代码粘贴到模块窗口中,然后按 F5 运行代码。


推荐阅读