Skip to main content

如何將Word文檔中的每頁保存為單獨的PDF文件?

Author: Siluvia Last Modified: 2025-05-13

在 Microsoft Word 中,您可以手動使用內建的「另存為」功能,並在「選項」對話框中指定頁碼,從而將每頁保存為單獨的 PDF 文件。然而,如果您正在處理包含數百頁的大型文檔,手動操作可能會非常耗時。本文介紹了一種快速將所有頁面保存為單獨 PDF 文件的方法。

使用 VBA 代碼批量將每頁保存為單獨的 PDF 文件


使用 VBA 代碼批量將每頁保存為單獨的 PDF 文件

您可以使用以下 VBA 代碼自動將 Word 文檔中的每頁保存為單獨的 PDF 文件。具體操作步驟如下:

  1. 打開要處理的 Word 文檔。按下 Alt + F11 鍵以打開 Microsoft Visual Basic for Applications 窗口。
  2. 在 Visual Basic 窗口中,點擊「插入」>「模塊」,然後將以下 VBA 代碼粘貼到模塊窗口中:
    Sub SaveAsSeparatePDFs()
    'Updated by Extendoffice 20180906
        Dim I As Long
        Dim xStr As String
        Dim xPathStr As Variant
        Dim xDictoryStr As String
        Dim xFileDlg As FileDialog
        Dim xStartPage, xEndPage As Long
        Dim xStartPageStr, xEndPageStr As String
        Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
        If xFileDlg.Show <> -1 Then
            MsgBox "Please chose a valid directory", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        xPathStr = xFileDlg.SelectedItems(1)
        xStartPageStr = InputBox("Begin saving PDFs starting with page __? " & vbNewLine & "(ex: 1)", "Kutools for Word")
        xEndPageStr = InputBox("Save PDFs until page __?" & vbNewLine & "(ex: 7)", "Kutools for Word")
        If Not (IsNumeric(xStartPageStr) And IsNumeric(xEndPageStr)) Then
            MsgBox "The enterng start page and end page should be number format", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        xStartPage = CInt(xStartPageStr)
        xEndPage = CInt(xEndPageStr)
        If xStartPage > xEndPage Then
            MsgBox "The start page number can't be larger than end page", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        If xEndPage > ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) Then
            xEndPage = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
        End If
        For I = xStartPage To xEndPage
            ActiveDocument.ExportAsFixedFormat xPathStr & "\Page_" & I & ".pdf", _
            wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportFromTo, I, I, wdExportDocumentWithMarkup, _
            False, False, wdExportCreateHeadingBookmarks, True, False, False
        Next
    End Sub
    VBA window with Insert > Module selected and VBA code copied into the Module window
  3. 按下 F5 鍵運行代碼。
  4. 在彈出的瀏覽窗口中,選擇一個文件夾來保存 PDF 文件,然後點擊「確定」。
    Browse window
  5. 在第一個「Kutools for Word」對話框中,輸入起始頁碼,然後點擊「確定」。
    Kutools for Word dialog box with a text box for entering the start page number
  6. 在第二個「Kutools for Word」對話框中,輸入結束頁碼,然後點擊「確定」。
    Second Kutools for Word dialog box with a text box for entering the last page number

    注意:例如,要保存幾頁連續的頁面(第 4、5 和 6 頁),只需在兩個對話框中分別輸入「4」和「6」即可。

腳本運行完成後,前往您在步驟 4 中選擇的文件夾。您會發現每個指定的頁面都已保存為單獨的 PDF 文件:

Pages are split and saved as individual PDF files

輕鬆將 Word 文檔拆分為多個文檔
使用文件拆分工具,輕鬆將 Word 文檔拆分為多個文檔。無需手動複製和粘貼,此工具可讓您根據頁面標題 1分頁符分節符來拆分文檔,大幅提升效率。
A screenshot of the Split Document utility splitting a Word document by page
Kutools for Word:透過數百種實用工具提升您的 Word 體驗。立即下載並親眼見證差異!

最佳辦公效率工具

Kutools for Word - 透過超過 100 項卓越功能提升您的 Word 體驗!

🤖 Kutools AI 功能AI助手 / 即時助手 / 超級潤色(保留格式)/ 超級翻譯(保留格式)/ AI遮擋 / AI校正...

📘 文件精通拆分頁面 / 合併文檔 / 以多種格式導出選擇內容(PDF/TXT/DOC/HTML...)/ 批量轉換為 PDF...

內容編輯跨多個文件進行批量查找和替換 / 調整所有圖片大小 / 翻轉表格的行與列 / 表格轉文本...

🧹 輕鬆清理:清除多餘空格 / 分節符 / 文本框 / 超鏈接 / 更多清除工具,請前往“清除”組...

創意插入:插入千位分隔符 / 複選框 / 選項按鈕 / 二維碼 / 條形碼 / 多張圖片 / 在“插入”組中發現更多...

🔍 精確選擇:精準定位特定頁面 / 表格 / 形狀 / 標題段落 / 使用更多選擇 ”功能增強導航...

星級增強功能跳轉至任意位置 / 自動插入重複文本 / 在文檔窗口之間切換 / 11 轉換工具...

Kutools and Kutools Plus tabs on the Word Ribbon
👉 想要試用這些功能嗎?立即下載 Kutools for Word!🚀
 

最佳辦公效率工具

Kutools for Word - 100+ Word 工具