วันพฤหัสบดีที่ 28 มีนาคม 2024
  2 ตอบกลับ
  เยี่ยมชม 1.3 พันครั้ง
0
โหวต
แก้
สวัสดี
ตามโพสต์นี้
https://www.extendoffice.com/documents/word/5415-split-word-document-every-x-pages.html#a1
ได้โปรดฉันต้องการแนวคิดเดียวกัน แต่มีจำนวนคำ
ดังนั้นฉันจึงต้องการแยกเอกสารคำทุกๆ 14000 คำในโฟลเดอร์เดียวกัน
ขอบคุณ
1 เดือนที่ผ่านมา
·
#8584
0
โหวต
แก้
สวัสดี,

เราจะนำข้อเสนอแนะของคุณไปพิจารณาเพื่อรวมไว้ในฟีเจอร์เวอร์ชันต่อๆ ไปอย่างแน่นอน! ขอบคุณสำหรับข้อมูลอันมีค่าของคุณ!

และฉันได้สร้างโค้ด VBA ด้านล่างโดยใช้ Kutools AI Aide และทดสอบสำเร็จแล้ว โปรดลองใช้ดู:

หมายเหตุ: ตรวจสอบให้แน่ใจว่าคุณได้สำรองข้อมูลเอกสารของคุณก่อนที่จะรันสคริปต์ VBA นี้เพื่อป้องกันปัญหาที่อาจเกิดขึ้นหรือเพื่อคืนค่าการเปลี่ยนแปลงหากจำเป็น

Sub SplitDocumentEvery14000Words()
Dim originalDoc As Document
Set originalDoc = ActiveDocument

Dim wordCount As Long
wordCount = 0

Dim docIndex As Integer
docIndex = 1

Dim newDoc As Document
Set newDoc = Documents.Add

Dim originalDocPath As String
originalDocPath = originalDoc.Path

Dim i As Long
For i = 1 To originalDoc.Words.Count
wordCount = wordCount + 1
newDoc.Content.InsertAfter originalDoc.Words(i).Text

' Split and save every 14000 words
If wordCount >= 14000 Then
' Reset word count
wordCount = 0

' Save the document
newDoc.SaveAs2 FileName:=originalDocPath & "\SplitDoc_" & docIndex & ".docx"

' Prepare for next document
docIndex = docIndex + 1
Set newDoc = Documents.Add
End If
Next i

' Save the last document if it has content
If newDoc.Content.Words.Count > 1 Then
newDoc.SaveAs2 FileName:=originalDocPath & "\SplitDoc_" & docIndex & ".docx"
Else
newDoc.Close False
End If

MsgBox "Documents have been split successfully."
End Sub


โปรดแจ้งให้เราทราบหากคุณประสบปัญหาใดๆ หรือมีอะไรอื่นที่เราสามารถช่วยคุณได้

อแมนดา
1 เดือนที่ผ่านมา
·
#8585
0
โหวต
แก้
ขอบคุณสำหรับคำตอบของคุณอแมนดา :)
ฉันรันโค้ด VBA แต่ใช้เวลานานโดยไม่มีผลลัพธ์ใดๆ (ไม่ตอบสนอง)
Word ค้างและขัดข้องและมีเสียงพัดลมแม้ว่าฉันจะมีแล็ปท็อปที่มี RAM 16GB, M.256 NVMe SSD 2GB และ HDD 1TB
ขอบคุณ
  • หน้า:
  • 1
ไม่มีคำตอบสำหรับโพสต์นี้