跳到主要内容

如何在Excel中的单元格/页眉/页脚中插入页码?

当您打印Excel文件时,可能需要在页中插入页码,以使文件清晰,可读。 在本文中,我将介绍一些快速技巧,为您插入页码到单元格,页眉或页脚中。

在一个工作表的页眉/页脚中插入页码

在多个工作表的页眉/页脚中插入页码

用VBA代码将页码插入单元格

在Excel中一次删除所有页码


箭头蓝色右气泡 在一个工作表的页眉/页脚中插入页码

通常,我们可以使用来快速将页码插入页眉或页脚 页眉页脚 功能,请执行以下操作:

1。 转到要在页眉或页脚中插入页码的工作表。

2。 然后点击 插页 > 页眉页脚,您的工作表将在 页面布局 查看,查看截图:

doc插入页码1

3。 单击要在其中插入页码的页眉或页脚,然后单击 设计页眉和页脚工具 显示在功能区中,然后单击 设计 > 页码,请参见屏幕截图:

doc插入页码2

4。 您会看到占位符 &[页] 出现在所选部分中,然后单击页眉或页脚区域之外的任何位置以显示页码。 看截图:

doc插入页码3

5。 现在,您可以通过以下方式重置为普通视图: 查看 > 正常,并且在打印此工作表时,您将看到页码已插入到所选的页眉或页脚中。

备注:如果要以1之15、2之15格式显示页码,则只需直接输入 &[页面]中的&[页面] 进入页眉或页脚字段框,请参见屏幕截图:

doc插入页码4


箭头蓝色右气泡 在多个工作表的页眉/页脚中插入页码

上面的方法可以帮助您将页码插入一个工作表中,如果您要将页码插入工作簿的所有工作表中以使所有页面都按顺序编号,请执行以下操作:

1. 选择所有工作表标签,然后转到 页面布局 选项卡,然后单击 对话框启动器按钮 中的图标 页面设置 组,请参见屏幕截图:

doc插入页码5

2。 在 页面设置 对话框,请单击 页眉页脚 标签,然后单击 自定义标题 or 自定义页脚 要设置所需的页眉或页脚,请参见屏幕截图:

doc插入页码6

3. 而在 标题 or 页脚 对话框中,请在页面的内部单击以定义插入页码的位置 左侧部分:, 中心部分:右侧部分: 您需要的框,然后单击 插入页码 图标和占位符 &[页] 出现。 看截图:

doc插入页码7

请注意: 输入这个 &[页面]中的&[页面] 如果您希望将页码显示为1中的45、2中的45…,则将其添加到页眉或页脚字段框中

4. 然后点击 OK > OK 若要关闭对话框,当您打印此工作簿时,在打印预览中,您可以看到所有页码均按顺序插入页眉或页脚。


箭头蓝色右气泡 用VBA代码将页码插入单元格

将页码插入页眉或页脚很容易,但是,如果您需要将页码插入工作表单元格,则没有直接的方法。 以下VBA代码可以帮助您解决此问题。

1。 单击要在其中显示该单元的页码的单元格。

2。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

3。 点击 插页 > 模块,然后将以下代码粘贴到 模块 窗口。

VBA代码:将当前页码插入单元格:

Sub pagenumber()
'updateby Extendoffice 20160506
    Dim xVPC As Integer
    Dim xHPC As Integer
    Dim xVPB As VPageBreak
    Dim xHPB As HPageBreak
    Dim xNumPage As Integer
    xHPC = 1
    xVPC = 1
    If ActiveSheet.PageSetup.Order = xlDownThenOver Then
        xHPC = ActiveSheet.HPageBreaks.Count + 1
    Else
        xVPC = ActiveSheet.VPageBreaks.Count + 1
    End If
    xNumPage = 1
    For Each xVPB In ActiveSheet.VPageBreaks
        If xVPB.Location.Column > ActiveCell.Column Then Exit For
        xNumPage = xNumPage + xHPC
    Next
    For Each xHPB In ActiveSheet.HPageBreaks
        If xHPB.Location.Row > ActiveCell.Row Then Exit For
        xNumPage = xNumPage + xVPC
    Next
    ActiveCell = "Page " & xNumPage & " of " & Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
End Sub

4。 然后按 F5 键以运行此代码,并且该单元格的页码显示在所选单元格中,请参见屏幕截图:

doc插入页码8


箭头蓝色右气泡 在Excel中一次删除所有页码

要删除所有页码,可以应用以下步骤:

1。 选择所有工作表标签,然后转到 页面布局 功能区上的标签,然后单击 对话框启动器按钮 中的图标 页面设置 组,请参见屏幕截图:

doc插入页码9

2。 在 页面设置 对话框,单击 页眉页脚 标签,然后选择 (无) 来自 标题 or 页脚 下拉列表,请参见屏幕截图:

doc插入页码10

3. 然后点击 OK 按钮,立即将所有页码从工作簿中删除。

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!

 

Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hay forma de convertir esta sub en una función?
This comment was minimized by the moderator on the site
Hola,el codigo si me funciono, sin embargo al momento de imprimir, siempre me sale 1 de 5 y es que mi encabezado lo tengo como área de impresión en todas mis paginas, ¿hay alguna forma de lograr que al momento de imprimir, se pueda cambiar la pagina, en la misma pestaña?
This comment was minimized by the moderator on the site
May I know how I should modify above VBA that allows me to execute this to range of cells on a workbook and with 1 short cut key to apply all selected cells?
This comment was minimized by the moderator on the site
May I know if I have range of cells that I want to put in page numbers, what should I change? The current VBA only allows me to change one by one.
This comment was minimized by the moderator on the site
terima kasih, kawan
This comment was minimized by the moderator on the site
Hola, hay un error en la formula porque cuando ejecuto (F5) el primer valor numérico de "Pagina XX de XX" no cambia. Solo hace el conteo de páginas el segundo valor. Podrian revisar... Gracias
This comment was minimized by the moderator on the site
I tried the VBA macro, but I'm getting a subscript out of range error... Did I do something wrong?
This comment was minimized by the moderator on the site
Hello I used the Insert page number into cell with VBA code above and it works a charm. My sheet could be either 2 pages long (2 down and 1 across), 4 pages long (2 down and 2 across) or 6 pages long (2 down and 3 across). I have inserted the code in each cell of the 6 that require page number to be printed (by selecting the cells each in turn and running the VBA), cell addresses are H1, H35, T1, T35, AF1, AF35. Now I would like to add a button to refresh these page numbers without affecting whichever cell may be active when the relevant user may choose to run it, currently I have to select each cell in turn again and run the VBA :( Assistance would be hugely appreciated! Antoinette
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations