Skip to main content

Kutools for Office — 一套工具,五種功能。完成更多工作。

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

Author Siluvia Last modified

在 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 FeaturesAI AssistantReal-Time AssistantSuper Polish(保留格式)Super Translate(保留格式)AI RedactionAI Proofread...

📘 文件掌握分割頁面文檔合併區域導出成各種格式(PDF/TXT/DOC/HTML...)批量轉換為 PDF...

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

🧹 輕鬆清理:快速清除多餘空格分節符文字框超連結/更多清除工具請前往刪除工具組...

創意插入:插入千位分隔符複選框選項按鈕二維碼條形碼批量插入圖片/還有更多精彩功能在插入工具組...

🔍 精確選擇:精確定位特定頁面表格形狀標題段落/使用更多 選擇 功能提升導航效率...

亮點增強導航至任何區域自動插入重複文字切換文檔窗口11 轉換工具...

🌍 支援40+種語言:可用 Kutools於您偏好語言環境——支援英語、西班牙語、德語、法語、中文以及超過40種語言!

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

✨ Kutools for Office——一次安裝,五大強力工具!

包含 Office Tab Pro · Kutools for Excel · Kutools for Outlook · Kutools for Word · Kutools for PowerPoint

📦 五大工具一次全擁有 | 🔗 與 Microsoft Office 無縫整合 | ⚡ 即刻省時提高工作效率

最佳辦公效率工具

Kutools for Word - 100+ 款 Word 工具