跳至主要内容

如何将Word文档中的每一页保存为单独的PDF文件?

Author: Siluvia Last Modified: 2025-05-07

在 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 工具