看看代码:Sub mynzdetp()Dim myParagraph As Paragraph, n As IntegerApplication.ScreenUpdating = Falsen = 1For Each myParagraph In ActiveDocument.ParagraphsIf Len(Trim(myParagraph.Range)) = 1 ThenmyParagraph.Range.Deleten = n + 1NextMsgBox 本次共删除空白段落 n - 1 个Application.ScreenUpdating = True代码截图:


代码的讲解:①Dim myParagraph As Paragraph, n As Integer 定义段落和删除数量的自变量②Application.ScreenUpdating = False 关闭屏幕刷新③然后将用一个FOR EACH 循环来遍历每个段落④当Len(Trim(myParagraph.Range)) = 1时那么将删除这个段落,大家是否理解这句的含义呢?一会儿我们做做测试。⑤myParagraph.Range.Delete 如果Len(Trim(myParagraph.Range)) = 1成立那么将删除这段n = n + 1 段落的标识增加1我们先看看代码的运行:运行前:


运行后:



我们在原页面中按下shift+ctrl+8 看看页面的样子:


相信你看了上面的截图一定明白了Len(Trim(myParagraph.Range)) = 1的意义了吧。今日内容回向:1 利用VBA代码如何删除空的段落?2 空的段落的意义是什么