สวัสดี,
เราจะนำข้อเสนอแนะของคุณไปพิจารณาเพื่อรวมไว้ในฟีเจอร์เวอร์ชันต่อๆ ไปอย่างแน่นอน! ขอบคุณสำหรับข้อมูลอันมีค่าของคุณ!
และฉันได้สร้างโค้ด 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
โปรดแจ้งให้เราทราบหากคุณประสบปัญหาใดๆ หรือมีอะไรอื่นที่เราสามารถช่วยคุณได้
อแมนดา