Loncat ke daftar isi utama

Bagaimana cara membagi dokumen Word menjadi file terpisah setiap 5 atau n halaman?

Jika Anda memiliki dokumen Word berukuran besar yang berisi ratusan halaman, dan sekarang, Anda ingin membagi dokumen ini menjadi file terpisah setiap 10 atau n halaman. Adakah cara cepat dan mudah untuk menyelesaikan pekerjaan ini tanpa menyalin dan menempel halaman satu per satu?

Pisahkan dokumen Word menjadi file terpisah setiap 10 atau n halaman dengan kode VBA

Pisahkan dokumen Word menjadi file terpisah setiap 10 atau n halaman dengan fitur luar biasa


Pisahkan dokumen Word menjadi file terpisah setiap 10 atau n halaman dengan kode VBA

Untuk membagi dokumen besar menjadi beberapa file terpisah berdasarkan setiap 10 atau n halaman, kode VBA berikut dapat membantu Anda, lakukan seperti ini:

1. Tahan ALT + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Dan kemudian, klik Menyisipkan > Modul, salin dan tempel kode di bawah ini ke dalam modul kosong yang dibuka:

Kode VBA: Pisahkan dokumen menjadi file terpisah setiap 10 atau n halaman:

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. Setelah menempelkan kode di atas, masih di Microsoft Visual Basic untuk Aplikasi jendela, silakan klik Tools > Referensi, dan di munculkan Referensi-Proyek kotak dialog, periksa Ekspresi Reguler Microsoft VBScript 5.5 pilihan dalam Referensi yang Tersedia kotak daftar, lihat tangkapan layar:

4. Lalu klik OK tombol, lalu tekan F5 kunci untuk menjalankan kode ini, dan a Jelajahi Folder kotak dialog ditampilkan, pilih folder tempat Anda ingin meletakkan file terpisah, lihat tangkapan layar:

5. Lalu klik OK tombol, dan kotak prompt lain muncul untuk mengingatkan Anda memasukkan nomor jumlah halaman yang ingin Anda bagi berdasarkan, lihat tangkapan layar:

6. Dan kemudian klik OK tombol, dokumen Word aktif telah dipecah menjadi file terpisah setiap 10 halaman, Anda dapat pergi ke folder yang ditentukan untuk melihat hasilnya:


Pisahkan dokumen Word menjadi file terpisah setiap 10 atau n halaman dengan fitur luar biasa

Kutools for Word termasuk fitur yang kuat- Split fungsi, dengan utilitas ini, Anda dapat dengan cepat membagi dokumen Word yang besar menjadi beberapa file terpisah berdasarkan Heading1, page break, section break, dan page.

Tip:Untuk menerapkan ini Split fitur, pertama, Anda harus mengunduh Kutools for Word, lalu terapkan fitur dengan cepat dan mudah.

Setelah menginstal Kutools for Word, lakukan seperti ini:

1. Klik Kutools Ditambah > Split, lihat tangkapan layar:

2. Di kotak dialog yang muncul, silakan atur operasi berikut yang Anda butuhkan, lihat tangkapan layar:

3. Setelah menyelesaikan pengaturan, silakan klik OK, dan seluruh dokumen akan dipecah menjadi beberapa file berdasarkan setiap halaman, lihat tangkapan layar:

Klik untuk mengunduh Kutools for Word dan uji coba gratis sekarang!

Alat Produktivitas Kantor Terbaik

Kutools for Word - Tingkatkan Pengalaman Kata Anda dengan Over 100 Fitur Luar Biasa!

🤖 Asisten AI Kutools: Ubah tulisan Anda dengan AI - Hasilkan Konten  /  Menulis Ulang Teks  /  Meringkas Dokumen  /  Menanyakan Informasi berdasarkan Dokumen, semuanya dalam Word

📘 Penguasaan Dokumen: Halaman Terpisah  /  Gabungkan Dokumen  /  Ekspor Pilihan dalam Berbagai Format (PDF/TXT/DOC/HTML...)  /  Konversi Batch ke PDF  /  Ekspor Halaman sebagai Gambar  /  Cetak Banyak File sekaligus...

Pengeditan Isi: Temukan dan Ganti Batch di Banyak File  /  Ubah Ukuran Semua Gambar  /  Ubah Urutan Baris dan Kolom Tabel  /  Ubah Tabel menjadi Teks...

🧹 Bersih dengan Mudah: Menyapu Spasi Ekstra  /  Bagian Istirahat  /  Semua Header  /  Teks box  /  Hyperlink  / Untuk alat penghapus lainnya, kunjungi kami Hapus Grup...

Sisipan Kreatif: Memasukkan Seribu Pemisah  /  Kotak Centang  /  Tombol Radio  /  Kode QR  /  barcode  /  Tabel Garis Diagonal  /  Keterangan Persamaan  /  Keterangan gambar  /  Keterangan Tabel  /  Banyak Gambar  / Temukan lebih lanjut di Sisipkan Grup...

🔍 Pilihan Presisi: Tepat halaman tertentu  /  tabel  /  bentuk  /  paragraf judul  / Tingkatkan navigasi dengan lebih Pilih fitur...

Peningkatan Bintang: Navigasi dengan cepat ke lokasi mana pun  /  menyisipkan teks berulang secara otomatis  /  beralih antar jendela dokumen dengan mulus  /  11 Alat Konversi...

👉 Ingin mencoba fitur-fitur tersebut? Kutools for Word menawarkan a Uji coba gratis 60-hari, tanpa batasan! 🚀
 
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