|
楼主 |
发表于 2022-7-2 00:16
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
谢谢大家。我已写好代码,测试通过,分享如下:
Sub 删除错误分段2()
Dim Pr As Paragraph
Dim i As Long
On Error Resume Next
'先删除空行
For Each Pr In ActiveDocument.Paragraphs
With Pr.Range
If Len(Trim(.Text)) = 1 Then .Delete '删除空行
End With
Next
'再删除断段
For i = 1 To ActiveDocument.Paragraphs.Count
With ActiveDocument.Paragraphs(i).Range
If Len(.Text) > 2 Then
If Not InStrRev(.Text, ".", -1) = Len(.Text) - 1 Then '如果断段没有句号
If Not UCase(Left(ActiveDocument.Paragraphs(i + 1).Range.Text, 1)) = Left(ActiveDocument.Paragraphs(i + 1).Range.Text, 1) Then '如果下一段首字母是小写
.Text = Left(.Text, Len(.Text) - 1)'删除段落标记
End If
End If
End If
End With
Next
End Sub
|
|