跳至主要内容

如何将Word文档每5页或n页拆分为单独的文件?

Author: Xiaoyang Last Modified: 2025-05-07

在处理大型Word文档时,您可能需要将文档拆分为较小的独立文件,以便于处理、共享或编辑。每隔5页、10页或指定数量的页面拆分文档可以是更高效管理冗长内容的实用解决方案。

手动逐页复制和粘贴既耗时又低效。在本教程中,我们将介绍快速简便的方法,将Word文档每N页拆分为单独的文件:

使用VBA代码将Word文档每N页拆分为单独的文件

使用一项强大功能将Word文档每N页拆分为单独的文件


使用VBA代码将Word文档每N页拆分为单独的文件

要将大型文档基于每N页拆分为单独的文件,以下VBA代码可以帮助您。请按照以下步骤操作:

  1. 按住ALT + F11打开Microsoft Visual Basic for Applications窗口。
  2. 点击插入 > 模块,并将以下代码复制粘贴到空白模块中:
  3. Sub DocumentSplitter()
        Dim xDoc As Document, xNewDoc As Document
        Dim xSplit As String, xCount As Long, xLast As Long
        Dim xRngSplit As Range, xDocName As String, xFileExt As String
        Dim xRegEx As RegExp
        Dim xPageCount As Integer
        Dim xShell As Object, xFolder As Object, xFolderItem As Object
        Dim xFilePath As String
        On Error Resume Next
        Set xDoc = Application.ActiveDocument
        Set xShell = CreateObject("Shell.Application")
        Set xFolder = xShell.BrowseforFolder(0, "Select a Folder:", 0, 0)
        If TypeName(xFolder) = "Nothing" Then Exit Sub
        Set xFolderItem = xFolder.Self
        xFilePath = xFolderItem.Path & "\"
        Application.ScreenUpdating = False
        Set xNewDoc = Documents.Add(Visible:=False)
        xDoc.Content.WholeStory
        xDoc.Content.Copy
        xNewDoc.Content.PasteAndFormat wdFormatOriginalFormatting
        With xNewDoc
            xPageCount = .ActiveWindow.Panes(1).Pages.Count
    L1:     xSplit = InputBox("The document contains " & xPageCount & " pages." & _
                     vbCrLf & vbCrLf & "Please enter the number of pages per split:", "Kutools for Word", xSplit)
            If Len(Trim(xSplit)) = 0 Then Exit Sub
            Set xRegEx = New RegExp
            With xRegEx
                .MultiLine = False
                .Global = True
                .IgnoreCase = True
                .Pattern = "[^0-9]"
            End With
            If xRegEx.Test(xSplit) = True Then
                MsgBox "Please enter a valid page number:", vbInformation, "Kutools for Word"
                Exit Sub
            End If
            If VBA.Int(xSplit) >= xPageCount Then
                MsgBox "The entered number exceeds the total page count of the document." & vbCrLf & "Please enter a valid number.", vbInformation, "Kutools for Word"
                GoTo L1
            End If
            xDocName = xDoc. Name
            xFileExt = VBA.Right(xDocName, Len(xDocName) - InStrRev(xDocName, ".") + 1)
            xDocName = Left(xDocName, InStrRev(xDocName, ".") - 1) & "_"
            xFilePath = xFilePath & xDocName
            For xCount = 0 To Int(xPageCount / xSplit)
                xPageCount = .ActiveWindow.Panes(1).Pages.Count
                If xPageCount > xSplit Then
                    xLast = xSplit
                Else
                    xLast = xPageCount
                End If
                Set xRngSplit = .GoTo(What:=wdGoToPage, Name:=xLast)
                Set xRngSplit = xRngSplit.GoTo(What:=wdGoToBookmark, Name:="\page")
                xRngSplit.Start = .Range.Start
                xRngSplit.Cut
                Documents.Add
                Selection.Paste
                ActiveDocument.SaveAs FileName:=xFilePath & xCount + 1 & xFileExt, AddToRecentFiles:=False
                ActiveWindow.Close
            Next xCount
            Set xRngSplit = Nothing
            xNewDoc.Close wdDoNotSaveChanges
            Set xNewDoc = Nothing
        End With
        Application.ScreenUpdating = True
    End Sub
  4. 粘贴代码后,仍然在 Microsoft Visual Basic for Applications 窗口中,点击 工具 > 引用。在 引用 - 项目 对话框中,勾选 Microsoft VBScript 正则表达式 5.5 选项,该选项位于 可用引用 列表中。参见截图:
    VBA window with Tools > References selected Arrow Microsoft VBScript Regular Expressions 5.5 checked in the References-Project dialog box
  5. 点击确定,然后按F5运行代码。
  6. 将出现一个浏览文件夹对话框。选择要保存拆分文件的文件夹,然后点击确定
  7. Browse For Folder dialog box

  8. 另一个提示框将出现,要求输入您希望拆分的页数。输入所需的页数并点击确定
  9. Dialog box for entering the page number to split based on

  10. 文档将被每N页拆分为单独的文件。导航到指定的文件夹查看结果。
  11. The document is split into separate files every N pages


使用一项强大功能将Word文档每N页拆分为单独的文件

Kutools for Word提供了一个强大的文档拆分功能,使您可以根据标题1、分页符、分节符或页面快速将大型Word文档拆分为多个独立文件。此功能简化了原本繁琐的手动过程。

Kutools for Word内置 AI 🤖,提供超过 100 种实用功能,助您简化任务。
  1. 点击 Kutools Plus > 文档拆分.

    Split button on the Kutools tab on the ribbon

  2. 在弹出的对话框中,根据需要配置以下选项:
    1. 类型菜单中选择文档页码倍数选项。
    2. 在输入框中指定n值。
    3. 选择保存位置。
    4. 为拆分的文档指定前缀。

      Split Document dialog box

  3. 完成设置后,点击 确定。文档将根据所选选项(例如,每7页)拆分为多个文件。

    The document is split into separate files every N pages

使用Kutools for Word中的文档拆分功能,可以轻松高效地将大型文档拆分为较小且易于管理的文件。

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