跳到主要內容

如何在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 for Applications 窗口。

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選項卡為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