Ga naar hoofdinhoud

Hoe een Word-document opsplitsen in afzonderlijke bestanden om de 5 of n pagina's?

Als u een groot Word-document heeft dat honderden pagina's bevat, en nu wilt u dit document opsplitsen in afzonderlijke bestanden om de 10 of n pagina's. Is er een snelle en gemakkelijke manier om deze taak op te lossen zonder de pagina's een voor een te kopiëren en te plakken?

Splits een Word-document in afzonderlijke bestanden om de 10 of n pagina's met VBA-code

Splits een Word-document in afzonderlijke bestanden om de 10 of n pagina's met een geweldige functie


Splits een Word-document in afzonderlijke bestanden om de 10 of n pagina's met VBA-code

Om een ​​groot document op te splitsen in afzonderlijke bestanden op basis van elke 10 of n pagina's, kan de volgende VBA-code u een plezier doen, doe dit als volgt:

1. Houd de ALT + F11 toetsen om de te openen Microsoft Visual Basic voor toepassingen venster.

2. En klik dan Invoegen > Module, kopieer en plak onderstaande code in de geopende lege module:

VBA-code: splits een document om de 10 of n pagina's in afzonderlijke bestanden:

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. Na het plakken van de bovenstaande code, nog steeds in het Microsoft Visual Basic voor toepassingen venster, klik dan Tools > Referenties, en in de pop eruit Referenties-Project dialoogvenster, vink aan Microsoft VBScript reguliere expressies 5.5 optie in het Beschikbare referenties keuzelijst, zie screenshot:

4. Dan klikken OK knop en druk vervolgens op F5 sleutel om deze code uit te voeren, en een Blader naar de map dialoogvenster wordt weergegeven, selecteer een map waarin u de gesplitste bestanden wilt plaatsen, zie screenshot:

5. Dan klikken OK knop, en een ander promptvenster verschijnt om u eraan te herinneren het aantal pagina's in te voeren dat u wilt splitsen op basis van, zie screenshot:

6. En klik vervolgens op OK knop, het actieve Word-document is om de 10 pagina's opgesplitst in afzonderlijke bestanden, u kunt naar de opgegeven map gaan om de resultaten te zien:


Splits een Word-document in afzonderlijke bestanden om de 10 of n pagina's met een geweldige functie

Kutools for Word bevat een krachtige functie- Split functie, kunt u met dit hulpprogramma snel een groot Word-document opsplitsen in meerdere afzonderlijke bestanden op basis van Heading1, pagina-einde, sectie-einde en pagina.

Tips:Om dit toe te passen Split -functie, ten eerste moet u de Kutools for Worden pas de functie vervolgens snel en gemakkelijk toe.

Na het installeren van Kutools for Word, doe dit als volgt:

1. Klikken Koetools Plus > Split, zie screenshot:

2. Stel in het uitgeklapte dialoogvenster de volgende bewerkingen in zoals u nodig hebt, zie screenshot:

3. Klik na het voltooien van de instellingen op OK, en het hele document wordt opgesplitst in meerdere bestanden op basis van elke pagina, zie screenshot:

Klik om Kutools voor Word en nu gratis uit te proberen!

Beste Office-productiviteitstools

Kutools for Word - Verbeter uw woordervaring met Over 100 Opmerkelijke kenmerken!

🤖 Kutools AI-assistent: Transformeer uw schrijven met AI - Inhoud genereren  /  Herschrijf tekst  /  Documenten samenvatten  /  Informeer voor informatie gebaseerd op document, allemaal binnen Word

📘 Documentbeheersing: Pagina's splitsen  /  Voeg documenten samen  /  Selectie exporteren in verschillende formaten (PDF/TXT/DOC/HTML...)  /  Batchconversie naar PDF  /  Pagina's exporteren als afbeeldingen  /  Meerdere bestanden tegelijk afdrukken...

Inhoud bewerken: Batch zoeken en vervangen over meerdere bestanden  /  Formaat van alle afbeeldingen wijzigen  /  Tabelrijen en -kolommen transponeren  /  Converteer tabel naar tekst...

🧹 Moeiteloos schoon: Veeg weg Extra ruimtes  /  Sectie-onderbrekingen  /  Alle koppen  /  Tekstvakken  /  hyperlinks  / Ga voor meer verwijdergereedschappen naar onze Groep verwijderen...

Creatieve invoegingen: Invoegen Duizend scheidingstekens  /  Vink vakjes aan  /  Radio knoppen  /  QR Code  /  Barcode  /  Diagonale lijntabel  /  Vergelijking bijschrift  /  Bijschrift bij afbeelding  /  Tabel titel  /  Meerdere afbeeldingen  / Ontdek meer in de Groep invoegen...

???? Precisieselecties: Vaststellen specifieke pagina's  /  tafels  /  vormen  /  kop paragrafen  / Verbeter de navigatie met meer Selecteer functies...

Sterverbeteringen: Navigeer snel naar elke locatie  /  automatisch herhaalde tekst invoegen  /  naadloos schakelen tussen documentvensters  /  11 Conversiehulpmiddelen...

👉 Wil je deze functies proberen? Kutools voor Word biedt een Gratis proefperiode van 60-dag, zonder beperkingen! 🚀
 
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