How to split a Word document into separate files every 5 or n pages?

If you have a lengthy Word document with hundreds of pages and you wish to split it into separate files every 10 or n pages, is there a quick and efficient method to accomplish this without the need for manual copying and pasting?

To split a large document into separate files, each containing 10 or n pages, the following VBA code can assist you. Please follow these steps:

  1. Press the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
  2. Click Insert > Module, and then copy and paste the code below into the newly opened module:
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)
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 page count you want to 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 the page number:”, vbInformation, “Kutools for Word”
Exit Sub
End If
If VBA.Int(xSplit) >= xPageCount Then
MsgBox “The number is greater than the document number.” & vbCrLf & “Please re-enter”, 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
xLast = xPageCount
End If
Set xRngSplit = .GoTo(What:=wdGoToPage, Name:=xLast)
Set xRngSplit = xRngSplit.GoTo(What:=wdGoToBookmark, Name:=”\page”)
xRngSplit.Start = .Range.Start
ActiveDocument.SaveAs FileName:=xFilePath & xCount + 1 & xFileExt, AddToRecentFiles:=False
Next xCount
Set xRngSplit = Nothing
xNewDoc.Close wdDoNotSaveChanges
Set xNewDoc = Nothing
End With
Application.ScreenUpdating = True
End Sub
  1. After pasting the code, in the Microsoft Visual Basic for Applications window, click Tools > References. In the References-Project dialog box, check the “Microsoft VBScript Regular Expressions 5.5” option in the Available References list box.
  2. Click OK, then press the F5 key to run the code. A “Browse For Folder” dialog box will appear; select the folder where you want to save the split files.How to split a Word document into separate files every 5 or n pages
  3. Click OK, and another prompt box will appear, asking you to enter the desired page count for splitting.
  4. Click OK, and the active Word document will be split into separate files, each containing 10 pages. Check the specified folder to view the results.
How to split a Word document into separate files every 5 or n pages

How to split a Word document into separate files every 5 or n pages
Compare items
  • Total (0)
Shopping cart