How to split a Word document into separate files every 5 or n pages?
If you have a large Word document which contains hundreds pages, and now, you would like to split this document into separate files every 10 or n pages. Is there any quick and easy way for solving this job without copying and pasting the pages one by one?
Split a Word document into separate files every 10 or n pages with VBA code
Split a Word document into separate files every 10 or n pages with an amazing feature
Split a Word document into separate files every 10 or n pages with VBA code
To split a large document into separate files based on every 10 or n pages, the following VBA code can do you a favor, please do as this:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. And then, click Insert > Module, copy and paste below code into the opened blank module:
VBA code: Split a document into separate files every 10 or n pages:
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 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
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
3. After pasting the above code, still in the Microsoft Visual Basic for Applications window, please click Tools > References, and in the popped out References-Project dialog box, check Microsoft VBScript Regular Expressions 5.5 option in the Available References list box, see screenshot:
4. Then click OK button, and then press F5 key to run this code, and a Browse For Folder dialog box is displayed, please select a folder where you want to put the split files in, see screenshot:
5. Then click OK button, and another prompt box is popped out to remind you entering the page count number that you want to split based on, see screenshot:
6. And then click OK button, the active Word document has been split into separate files every 10 pages, you can go the specified folder to see the results:
Split a Word document into separate files every 10 or n pages with an amazing feature
Kutools for Word includes a powerful feature- Split function, with this utility, you can quickly split a large Word document into multiple separate files based on Heading1, page break, section break and page.
Tips:To apply this Split feature, firstly, you should download the Kutools for Word, and then apply the feature quickly and easily.
After installing Kutools for Word, please do as this:
1. Click Kutools Plus > Split, see screenshot:
2. In the popped out dialog box, please set the following operations as you need, see screenshot:
3. After finishing the settings, please click OK, and the whole document will be split into multiple files based on each page, see screenshot:
Click to download Kutools for Word and free trial now!
Best Office Productivity Tools
Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!
🤖 Kutools AI Assistant: Transform your writing with AI - Generate Content / Rewrite Text / Summarize Documents / Inquire for Information based on Document, all within Word
📘 Document Mastery: Split Pages / Merge Documents / Export Selection in Various Formats (PDF/TXT/DOC/HTML...) / Batch Convert to PDF / Export Pages as Images / Print Multiple Files at once...
✏ Contents Editing: Batch Find and Replace across Multiple Files / Resize All Pictures / Transpose Table Rows and Columns / Convert Table to Text...
🧹 Effortless Clean: Sweap away Extra Spaces / Section Breaks / All Headers / Text Boxes / Hyperlinks / For more removing tools, head to the Remove group...
➕ Creative Inserts: Insert Thousand Separators / Check Boxes / Radio Buttons / QR Code / Barcode / Diagonal Line Table / Equation Caption / Image Caption / Table Caption / Multiple Pictures / Discover more in the Insert group...
🔍 Precision Selections: Pinpoint Specific Pages / Tables / Shapes / Heading Paragraphs / Enhance navigation with more Select features...
⭐ Star Enhancements: Navigate to Any Location / Auto-Insert Repetitive Text / Toggle Between Document Windows / 11 Conversion Tools...