Hi 'na,
Byddwn yn sicr yn cymryd eich awgrym i ystyriaeth i'w gynnwys mewn fersiynau o'r nodwedd yn y dyfodol! Diolch am eich mewnbwn gwerthfawr!
Ac, rydw i wedi cynhyrchu'r cod VBA isod gan ddefnyddio Kutools AI Aide a'i brofi'n llwyddiannus. Mae croeso i chi roi cynnig arni:
SYLWCH: Sicrhewch eich bod yn gwneud copi wrth gefn o'ch dogfen cyn gweithredu'r sgript VBA hon i ddiogelu rhag problemau posibl neu i ddychwelyd unrhyw newidiadau os oes angen.
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
Rhowch wybod i mi os ydych chi'n dod ar draws unrhyw broblemau neu os oes unrhyw beth arall y gallaf eich cynorthwyo ag ef.
Amanda