狂自私

导航

删除连续的空行

Sub DeleteConsecutiveEmptyParagraphs()
    paraCount = ActiveDocument.Paragraphs.Count
    idx = 2
    Do While idx < paraCount
        forward_Paragraph = Replace(Replace(ActiveDocument.Paragraphs(idx - 1).Range.Text, " ", ""), vbTab, "")
        now_Paragraph = Replace(Replace(ActiveDocument.Paragraphs(idx).Range.Text, " ", ""), vbTab, "")
        
        
        ' 这里可以判断长度是否为1或者通过replace函数删除段落符号(vbCr)(replace(text,vbCr,""))然后判断长度为0来实现。
        If Len(now_Paragraph) = 1 And Len(forward_Paragraph) = 1 Then
            ActiveDocument.Paragraphs(idx).Range.Delete
        Else
            idx = idx + 1
        End If
        paraCount = ActiveDocument.Paragraphs.Count
    Loop
End Sub

 

posted on 2024-06-03 17:06  狂自私  阅读(4)  评论(0编辑  收藏  举报