|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
在ming0018教师代码的基础上,完善一下排版情况,请老师勿责怪:
Sub main()
Dim doc As Document, Rng As Range, arr, lineCount%
Set doc = ActiveDocument: lineCount = 40
With doc.Content.Find
.Text = "A.[!^13]{1,}^13^13B.[!^13]{1,}^13^13C.[!^13]{1,}^13^13D.[!^13]{1,}^13"
.MatchWildcards = True
Do While .Execute
Set Rng = .Parent
Rng.Text = Replace(Rng.Text, Chr(13) & Chr(13), Chr(13))
If Len(Rng.Text) < lineCount Then
Rng.MoveEnd 1, -1
Rng.Text = Replace(Rng.Text, Chr(13), vbTab)
If Rng.ComputeStatistics(1) > 1 Then
doc.Undo
End If
ElseIf Len(Rng.Text) < lineCount * 3 Then
arr = Split(Rng.Text, Chr(13))
If Len(arr(0)) + Len(arr(1)) < lineCount - 2 And Len(arr(2)) + Len(arr(3)) < lineCount - 2 Then
Rng.Text = arr(0) & vbTab & arr(1) & Chr(13) & arr(2) & vbTab & arr(3) & Chr(13)
If Rng.ComputeStatistics(1) > 2 Then
doc.Undo
End If
ElseIf Len(arr(0)) + Len(arr(1)) < lineCount - 2 And Len(arr(2)) + Len(arr(3)) > lineCount - 2 Then
Rng.Text = arr(0) & vbTab & arr(1) & Chr(13) & arr(2) & Chr(13) & arr(3) & Chr(13)
ElseIf Len(arr(0)) + Len(arr(1)) > lineCount - 2 And Len(arr(2)) + Len(arr(3)) < lineCount - 2 Then
Rng.Text = arr(0) & Chr(13) & arr(1) & Chr(13) & arr(2) & vbTab & arr(3) & Chr(13)
ElseIf Len(arr(1)) + Len(arr(2)) < lineCount - 2 And Len(arr(2)) + Len(arr(3)) < lineCount - 2 Then
Rng.Text = arr(0) & Chr(13) & arr(1) & Chr(13) & arr(2) & vbTab & arr(3) & Chr(13)
ElseIf Len(arr(1)) + Len(arr(2)) < lineCount - 2 And Len(arr(2)) + Len(arr(3)) > lineCount - 2 Then
Rng.Text = arr(0) & Chr(13) & arr(1) & vbTab & arr(2) & Chr(13) & arr(3) & Chr(13)
End If
End If
Rng.Move 4
Loop
End With
End Sub
We meet by chance like patches of drifting duckweed,
May everything be fine with you everyday !
(你我萍水相逢,愿君一切安好!)
|
|