Skip to main content

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 our 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 swiftly to any location  /  auto-insert repetitive text  /  seamlessly toggle between document windows  /  11 Conversion Tools...

๐Ÿ‘‰ Want to try these features? Kutools for Word offers a 60-day free trial, with no limitations! ๐Ÿš€
Free Download     Read More     Buy Now
 
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
good things. i used it to split with 1 page 1 word document, it was successful except that each document (after split), it has 2 pages in total although 2nd page is always blank.ย 
This comment was minimized by the moderator on the site
this code gives compile error which shows user define type is not define
This comment was minimized by the moderator on the site
For me, the VBA creates a single document that is a copy of the original and that's it.
This comment was minimized by the moderator on the site
The 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.
Thanks anyway
This comment was minimized by the moderator on the site
Hello, 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!
This comment was minimized by the moderator on the site
VBA Script: Split a document into separate files every 10 or n pages not worked
This comment was minimized by the moderator on the site
Hello, Sergey,
The above code works well in my Word document, which Word version do you use?
And which step went wrong in your operation?
This comment was minimized by the moderator on the site
i have been trying to split a word file of 166 pages and it gives 166 files each with 166 pages?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations