其实你参照也一下,就通了。可惜了! '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-4-15 4:05:57
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
Sub ExampleForDelBlank()
Dim i As Paragraph, MyRange As Range, N As Integer, SelRange As Range
On Error Resume Next '忽略错误(此处必需)
If Selection.Type = wdSelectionIP Then MsgBox "您必须选定需要进行删除操作的区域!", _
vbOKOnly + vbInformation: Exit Sub '如果未选定区域则友情提示并退出程序运行
Set SelRange = Selection.Range '定义一个RANGE区域为选定区域
' With ActiveDocument '此处作为示例,定义一个RANGE区域为表1的开始到表2的结束
' Set SelRange = .Range(.Tables(1).Range.Start, .Tables(2).Range.End)
' End With
Application.ScreenUpdating = False '关闭屏幕更新
With SelRange
For Each i In .Paragraphs '在活动文档的段落集合中循环
If Len(i.Range) = 1 Then '如果为空白段落
'定义一个RANGE对象
Set MyRange = ActiveDocument.Range(i.Range.Start, i.Range.Next(1).Start + 1)
'如果在该RANGE中没有发现分节符或者分页符
If MyRange.Find.Execute(findtext:="^b") = False And MyRange.Find.Execute(findtext:="^m") = False Then
i.Range.Delete '删除该段落
N = N + 1 '计数
End If
End If
Next
MsgBox "WORD 共删除了" & N & "个空白段落", vbOKOnly + vbInformation
End With
Application.ScreenUpdating = True '恢复屏幕更新
End Sub
'---------------------- |