ไปยังเนื้อหาหลัก

วิธีการแยกเอกสารเป็นหลาย ๆ เอกสารใน Word?

หากคุณมีเอกสารคำศัพท์จำนวนมากซึ่งคุณต้องแบ่งออกเป็นหลาย ๆ เอกสารให้ใช้เวลาสักครู่เพื่ออ่านบทแนะนำนี้ บทช่วยสอนนี้จะแสดงวิธีการสองวิธีในการแยกเอกสารออกเป็นหลาย ๆ เอกสาร


แยกเอกสาร Word ตามตัวคั่นที่ระบุด้วย VBA

แทนที่จะแยกเอกสารออกเป็นหลาย ๆ เอกสารด้วยตนเองวิธีนี้จะแนะนำ VBA เพื่อแยกเอกสาร Word โดยใช้ตัวคั่นที่ระบุใน Word กรุณาดำเนินการดังนี้:

1. กด Alt + F11 คีย์ร่วมกันเพื่อเปิดหน้าต่าง Microsoft Visual Basic for Application

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลจากนั้นวางโค้ด VBA ด้านล่างลงในหน้าต่างโมดูลการเปิดใหม่

VBA: แยกเอกสาร Word ออกเป็นหลาย ๆ เอกสารโดยใช้ตัวคั่น

Sub SplitNotes(delim As String, strFilename As String)
Dim doc As Document
Dim arrNotes
Dim I As Long
Dim X As Long
Dim Response As Integer
arrNotes = Split(ActiveDocument.Range, delim)
Response = MsgBox("This will split the document into " & UBound(arrNotes) + 1 & " sections.Do you wish to proceed?", 4)
If Response = 7 Then Exit Sub
For I = LBound(arrNotes) To UBound(arrNotes)
If Trim(arrNotes(I)) <> "" Then
X = X + 1
Set doc = Documents.Add
doc.Range = arrNotes(I)
doc.SaveAs ThisDocument.Path & "\" & strFilename & Format(X, "000")
doc.Close True
End If
Next I
End Sub
Sub test()
'delimiter & filename
SplitNotes "///", "Notes "
End Sub

3. จากนั้นคลิก วิ่ง หรือกดปุ่ม F5 เพื่อใช้ VBA

4. ในเอกสาร Microsoft Word ที่เปิดขึ้นมาโปรดคลิกปุ่มใช่เพื่อดำเนินการต่อ

หมายเหตุ
(1) อย่าลืมเพิ่มตัวคั่นของคุณให้เหมือนกับ "///" ในการทดสอบย่อยของเอกสารระหว่างแต่ละส่วนของข้อความที่คุณต้องการแยก นอกจากนี้คุณสามารถเปลี่ยน "///" ไปยังตัวคั่นเพื่อตอบสนองความต้องการของคุณ
(2) คุณสามารถเปลี่ยนแปลงเอกสาร "หมายเหตุ" ในการทดสอบย่อยเพื่อให้เหมาะกับความต้องการของคุณ
(3) และเอกสารที่แยกจะถูกบันทึกไว้ที่เดียวกันกับไฟล์ต้นฉบับ
(4) คุณไม่จำเป็นต้องเพิ่มตัวคั่นที่ส่วนท้ายของไฟล์ต้นฉบับหากคุณทำจะมีเอกสารว่างหลังจากแยก

แยกเอกสาร Word ทีละหน้าด้วย VBA

นี่คือ VBA อีกตัวที่จะช่วยให้คุณแยกเอกสาร Word หนึ่งฉบับเป็นหลาย ๆ หน้าใน Word ได้อย่างรวดเร็ว กรุณาดำเนินการดังนี้:

1. กด Alt + F11 คีย์ร่วมกันเพื่อเปิดหน้าต่าง Microsoft Visual Basic for Application

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลจากนั้นวางโค้ด VBA ด้านล่างลงในหน้าต่างโมดูลการเปิดใหม่

VBA: แยกเอกสารออกเป็นหลาย ๆ เอกสารทีละหน้าใน Word

Sub SplitIntoPages()
Dim docMultiple As Document
Dim docSingle As Document
Dim rngPage As Range
Dim iCurrentPage As Integer
Dim iPageCount As Integer
Dim strNewFileName As String
Application.ScreenUpdating = False 'Makes the code run faster and reduces screen _
flicker a bit.
Set docMultiple = ActiveDocument 'Work on the active document _
(the one currently containing the Selection)
Set rngPage = docMultiple.Range 'instantiate the range object
iCurrentPage = 1
'get the document's page count
iPageCount = docMultiple.Content.ComputeStatistics(wdStatisticPages)
Do Until iCurrentPage > iPageCount
If iCurrentPage = iPageCount Then
rngPage.End = ActiveDocument.Range.End 'last page (there won't be a next page)
Else
'Find the beginning of the next page
'Must use the Selection object. The Range.Goto method will not work on a page
Selection.GoTo wdGoToPage, wdGoToAbsolute, iCurrentPage + 1
'Set the end of the range to the point between the pages
rngPage.End = Selection.Start
End If
rngPage.Copy 'copy the page into the Windows clipboard
Set docSingle = Documents.Add 'create a new document
docSingle.Range.Paste 'paste the clipboard contents to the new document
'remove any manual page break to prevent a second blank
docSingle.Range.Find.Execute Findtext:="^m", ReplaceWith:=""
'build a new sequentially-numbered file name based on the original multi-paged file name and path
strNewFileName = Replace(docMultiple.FullName, ".doc", "_" & Right$("000" & iCurrentPage, 4) & ".doc")
docSingle.SaveAs strNewFileName 'save the new single-paged document
iCurrentPage = iCurrentPage + 1 'move to the next page
docSingle.Close 'close the new document
rngPage.Collapse wdCollapseEnd 'go to the next page
Loop 'go to the top of the do loop
Application.ScreenUpdating = True 'restore the screen updating
'Destroy the objects.
Set docMultiple = Nothing
Set docSingle = Nothing
Set rngPage = Nothing
End Sub 

3. จากนั้นคลิก วิ่ง หรือกด F5 กุญแจสำคัญในการใช้ VBA

หมายเหตุ เอกสารที่แยกจะถูกบันทึกไว้ที่เดียวกันกับไฟล์ต้นฉบับ


แยกเอกสาร Word ตามส่วนหัว / หน้า / ส่วน / แบ่งหน้าโดยใช้ Kutools for Word

หากคุณติดตั้ง Kutools for Word คุณสามารถใช้ไฟล์ แยก ฟังก์ชั่นเพื่อแยกเอกสารหนึ่งเอกสารออกเป็นหลาย ๆ หน้าได้อย่างง่ายดายส่วนหัวส่วนแบ่งหรือตัวแบ่งหน้าตามที่คุณต้องการใน Word

Kutools สำหรับ Word เป็นโปรแกรมเสริม Word ขั้นสุดยอดที่ปรับปรุงการทำงานของคุณและเพิ่มทักษะการประมวลผลเอกสารของคุณ ทดลองใช้ฟรีสำหรับ 60 วัน! รับไปเดี๋ยวนี้เลย!

1.คลิก Kutools พลัส > แยก เพื่อเปิดใช้งาน แยก ลักษณะ

2. ในการเปิดกล่องโต้ตอบ Split ในหน้าจอคุณสามารถทำได้ดังนี้:

(1) เลือกวิธีการแยกจาก แยกตาม รายการแบบหล่นลง
คุณลักษณะนี้รองรับการแบ่ง 6 วิธี ได้แก่ ส่วนหัว 1 ตัวแบ่งหน้าตัวแบ่งส่วนหน้าทุก n หน้าและช่วงหน้าแบบกำหนดเองดังภาพด้านล่างที่แสดง:

(2) คลิกไฟล์ หมวดหมู่สินค้า ปุ่ม  เพื่อระบุ โฟลเดอร์ปลายทางที่คุณจะบันทึกเอกสารแยกเป็น;

(3) พิมพ์คำสำคัญเป็นคำนำหน้าชื่อเอกสารใหม่ในไฟล์ คำนำหน้าเอกสาร กล่อง.

ทิปส์:
(1) หากคุณระบุให้แยกเอกสารปัจจุบันด้วย ทุก n หน้าคุณต้องระบุหมายเลขในไฟล์ ทุก n หน้า กล่อง;

(2) หากคุณระบุให้แยกเอกสารปัจจุบันตามช่วงเพจที่กำหนดเองคุณต้องป้อนช่วงเพจที่กำหนดเองเหล่านี้โดยคั่นด้วยเครื่องหมายจุลภาคใน หน้า ตัวอย่างเช่นพิมพ์ 1, 3-5, 12 ในกล่อง

3. คลิก Ok ปุ่มเพื่อเริ่มการแยก

จากนั้นเอกสารปัจจุบันจะถูกแบ่งตามวิธีการแยกที่ระบุและเอกสารใหม่จะถูกบันทึกลงในโฟลเดอร์ปลายทางเป็นกลุ่ม

การท่องเว็บแบบแท็บและแก้ไขเอกสาร Word หลายรายการเช่น Firefox, Chrome, Internet Explore 10!

คุณอาจคุ้นเคยกับการดูหน้าเว็บหลายหน้าใน Firefox / Chrome / IE และสลับไปมาระหว่างหน้าเว็บเหล่านั้นโดยคลิกที่แท็บที่เกี่ยวข้องได้อย่างง่ายดาย ที่นี่ Office Tab รองรับการประมวลผลที่คล้ายกันซึ่งช่วยให้คุณสามารถเรียกดูเอกสาร Word หลายรายการในหน้าต่าง Word เดียวและสลับไปมาระหว่างเอกสารเหล่านี้ได้อย่างง่ายดายโดยคลิกที่แท็บ คลิกเพื่อทดลองใช้คุณสมบัติเต็มรูปแบบฟรี!
เรียกดูเอกสารหลายคำในหน้าต่างเดียวเป็น Firefox


บทความที่เกี่ยวข้อง:


สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

Kutools สำหรับ Word - ยกระดับประสบการณ์คำศัพท์ของคุณด้วย Over 100 คุณสมบัติเด่น!

🤖 Kutools ผู้ช่วย AI: แปลงโฉมงานเขียนของคุณด้วย AI - สร้างเนื้อหา  /  เขียนข้อความใหม่  /  สรุปเอกสาร  /  สอบถามข้อมูล ขึ้นอยู่กับเอกสารทั้งหมดนี้ภายใน Word

📘 ความเชี่ยวชาญด้านเอกสาร: แยกหน้า  /  ผสานเอกสาร  /  ส่งออกตัวเลือกในรูปแบบต่างๆ (PDF/TXT/DOC/HTML...)  /  แบทช์แปลงเป็น PDF  /  ส่งออกเพจเป็นรูปภาพ  /  พิมพ์หลายไฟล์พร้อมกัน...

การแก้ไขเนื้อหา: ค้นหาแบทช์และแทนที่ ข้ามหลายไฟล์  /  ปรับขนาดรูปภาพทั้งหมด  /  ย้ายแถวและคอลัมน์ของตาราง  /  แปลงตารางเป็นข้อความ...

🧹 ทำความสะอาดได้อย่างง่ายดาย: หลบไป พื้นที่พิเศษ  /  แบ่งส่วน  /  ส่วนหัวทั้งหมด  /  กล่องข้อความ  /  เชื่อมโยงหลายมิติ  / หากต้องการดูเครื่องมือถอดเพิ่มเติม โปรดไปที่ของเรา ลบกลุ่ม...

ส่วนแทรกโฆษณา: แทรก ตัวคั่นหลักพัน  /  กล่องกาเครื่องหมาย  /  ปุ่มวิทยุ  /  คิวอาร์โค้ด  /  บาร์โค้ด  /  ตารางเส้นทแยงมุม  /  คำอธิบายสมการ  /  คำบรรยายภาพ  /  คำบรรยายตาราง  /  รูปภาพหลายภาพ  / ค้นพบเพิ่มเติมใน แทรกกลุ่ม...

🔍 การเลือกที่แม่นยำ: ระบุ หน้าที่เฉพาะเจาะจง  /  ตาราง  /  รูปร่าง  /  หัวเรื่องย่อหน้า  / เสริมการนำทางด้วย ข้อมูลเพิ่มเติม เลือกคุณสมบัติ...

การปรับปรุงดาว: นำทางอย่างรวดเร็วไปยังสถานที่ใด ๆ  /  แทรกข้อความซ้ำอัตโนมัติ  /  สลับระหว่างหน้าต่างเอกสารได้อย่างราบรื่น  /  11 เครื่องมือการแปลง...

???? ต้องการลองใช้คุณสมบัติเหล่านี้หรือไม่? Kutools for Word มีไฟล์ ทดลองใช้ฟรี 60 วันโดยไม่มีข้อจำกัด! 🚀
 
Comments (45)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
VBA: Split Document into Multiple Documents by Page in Word - in this when we run it, outcome comes in portrait layout only. If original doc is in landscape then full data of the original doc does not come in the pages breaked by this vba.. There must be seperate vba for portrait and landscape docs.
This comment was minimized by the moderator on the site
I use the "split"-function of "Kutools For Word 9.00" with "header 1" and it works for 48 documents and then it simply stops without any message, as if it wohl have been finished. But I have 700 "header 1" in a 2000 pages document!
Is it simply too much for the tool or is there any other reason?
This comment was minimized by the moderator on the site
your code add new blank page in every page
This comment was minimized by the moderator on the site
This worked fine up until yesterday with Office365, but now I constantly get a runtime error '4605' stating this command is not available. Sometimes at the first page, sometimes at the 3rd page...I can't make it past 3 pages anymore. It happens with line 28 above...

docSingle.Range.Paste 'paste the clipboard contents to the new document
This comment was minimized by the moderator on the site
I've got this error too - Did you get anywhere with it?


Thanks
This comment was minimized by the moderator on the site
yes...i have to run it on the local hard drive. if i run it on a network file or with RemotePC it. has something to do with the script having to wait too long in between commands and it errors out copy and pasting to the clipboard. hope that helps!!
This comment was minimized by the moderator on the site
I copied the document distribution macro 'Split Word Document By Specified Delimiter With VBA', but in the line of 'sub test', the software reads it as a new macro and there are two macros here.
This comment was minimized by the moderator on the site
The script saves a two pages document, the second is total blank.

How to solve this?
This comment was minimized by the moderator on the site
Hi Jorge,
The VBA script introduced splits document by the separator “///”, and you do not need to add delimiter to the end of the original file, if you do, there will be a blank document after splitting.
This comment was minimized by the moderator on the site
Hi kellytte, Could you please explain a little further? I copy and paste the VBA script under the "Split Word by Document with VBA" from above and after I run the process following the instructions above, I always have to manually delete a 2nd blank page on each of the new documents that were created. Are you saying there is something that needs to be removed from the VBA script that will cause this to stop?
This comment was minimized by the moderator on the site
The split works great for me but on page in the merge file turns into 1.5 pages - something with the page layout (+ additional empty page at the end). any ideas how to go around that?
This comment was minimized by the moderator on the site
The Split Word By Document with VBA worked for me, but it is adding a blank page at the end of each document. Is there a way around this?
This comment was minimized by the moderator on the site
I am working on this as well but have not found a way to do it besides manually.
This comment was minimized by the moderator on the site
Does not work at all for me. Goes through the motions but no documents are saved. Maybe because I am using .DOCX files?
This comment was minimized by the moderator on the site
After playing with this code for over an hour I discovered you have to save the document you mail merged then you can run the code on the saved document that has all the pages you need to split up. Hope this helps.
This comment was minimized by the moderator on the site
I always start with a newly-saved document. I found the split documents were actually saved somewhere (I forget; doesn't matter) they were text only - all the formatting had been dropped.
This comment was minimized by the moderator on the site
Maybe something to do with Windows 7 settings? Thoughts from anyone?
This comment was minimized by the moderator on the site
Mais comment garder une mise en page complexe (image de fond, marges, etc) ?
Great but how to keep the lay-out (background image, margins ?)
This comment was minimized by the moderator on the site
Can you split the document based on Heading 1 styles as your "delimiter".
This comment was minimized by the moderator on the site
Hi Andrew,
The VBA script can split the entire document by page. If you need to split by heading 1, we suggest to try Kutools for Word’s Split (Document) feature.
This comment was minimized by the moderator on the site
Downloaded fodler doesnt open at all. Waiting for a long time.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations