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?
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:
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.
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:
Recommended Word Productivity Tools
- Complicated and repeated operations can be done one-time processing in seconds.
- Insert multiple images across folders into Word document at once.
- Merge and combine multiple Word files across folders into one with your desired order.
- Split the current document into separate documents according to heading, section break or other criteria.
- Convert files between Doc and Docx, Docx and PDF, collection of tools for common conversions and selection, and so on...
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 5 months agothis code gives compile error which shows user define type is not define
- To post as a guest, your comment is unpublished.· 1 years agoFor me, the VBA creates a single document that is a copy of the original and that's it.
- To post as a guest, your comment is unpublished.· 1 years agoThe VBscript code made Word crash. I was trying to split a 32Mb Word file with many pages but it seems Word can't handle it through VBscript.
- To post as a guest, your comment is unpublished.· 1 years agoHello, Studia,
The VBA code may crash when there is a large document, it is not stable, so I recommend you use our Kutools for Word tool, it has updated, and support to solve this task, you can download it and free trial 30 day.
Please try, thank you!
- To post as a guest, your comment is unpublished.· 1 years agoVBA Script: Split a document into separate files every 10 or n pages not worked
- To post as a guest, your comment is unpublished.· 1 years agoHello, Sergey,
The above code works well in my Word document, which Word version do you use?
And which step went wrong in your operation?
- To post as a guest, your comment is unpublished.· 1 years agoi have been trying to split a word file of 166 pages and it gives 166 files each with 166 pages?