Вы можете попробовать что-то на основе:
Sub TextSplitter()
Dim Rng As Range
Application.ScreenUpdating = False
With ActiveDocument
.Fields.Unlink
Set Rng = .Range(0, 0)
Do While Rng.End < .Range.End - 1
With Rng
.MoveEnd wdCharacter, 280
' Check whether the last character is a punctuation mark, paragraph break or line break
If Not .Characters.Last.Text Like "[.?!," & vbCr & Chr(11) & "]" Then
' Find the last preceding space
.End = .Start + InStrRev(Rng.Text, " ")
' Find the last preceding punctuation mark, paragraph break or line break
If InStr(.Text, ".") > 0 Then
.End = .Start + InStrRev(.Text, ".") + 1
ElseIf InStr(.Text, "?") > 0 Then
.End = .Start + InStrRev(.Text, "?") + 1
ElseIf InStr(.Text, "!") > 0 Then
.End = .Start + InStrRev(.Text, "!") + 1
ElseIf InStr(.Text, ",") > 0 Then
.End = .Start + InStrRev(.Text, ",") + 1
ElseIf InStr(Rng.Text, Chr(11)) > 0 Then
.End = .Start + InStrRev(.Text, Chr(11))
ElseIf InStr(Rng.Text, vbCr) > 0 Then
.End = .Start + InStrRev(.Text, vbCr)
End If
.Characters.Last.Text = vbCr
End If
DoEvents
.Collapse wdCollapseEnd
End With
Loop
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Имейте в виду, что с помощью приведенного выше кода, где диапазон содержит несколько знаков препинания и т. Д., Иерархия If / ElseIf определяет приоритет разделения, что можетприводят к тому, что более поздние знаки препинания в том же диапазоне игнорируются.
Следующий код использует другой подход, просто ищет последний знак препинания любого вида.
Sub TextSplitter()
Dim Rng As Range
Application.ScreenUpdating = False
With ActiveDocument
.Fields.Unlink
Set Rng = .Range(0, 0)
Do While Rng.End < .Range.End - 1
With Rng
.MoveEnd wdCharacter, 280
' Check whether the last character is not a punctuation mark, paragraph break or manual line break
If Not .Characters.Last.Text Like "[.?!," & vbCr & Chr(11) & "]" Then
' Find the last preceding space
.End = .Start + InStrRev(.Text, " ") + 1
' Find the last preceding punctuation mark, paragraph break or line break
With .Find
.Text = "[.\?\!,^13^11]"
.Replacement.Text = ""
.Forward = False
.Format = False
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
If .Find.Found = True Then
' Test the found character. If it's not a paragraph break, extend the range one character
If .Characters.Last.Text <> vbCr Then
If .Characters.Last.Text Like "[.?!,]" Then .End = .End + 1
End If
End If
' Replace the new last character with a paragraph break
.Characters.Last.Text = vbCr
' The Find was unsuccessful, so retest the last character for a line break
ElseIf .Characters.Last.Text = Chr(11) Then
' The last character is a manual line break, replace it with a paragraph break
.Characters.Last.Text = vbCr
Else
' The last character is a manual line break, so extend the range one character and
' replace the new last character with a paragraph break
.End = .End + 1
.Characters.Last.Text = vbCr
End If
DoEvents
.Collapse wdCollapseEnd
End With
Loop
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub