Word中怎么删除掉以特定符号开头的行?

以下代码同样适用于行和段落起始。(如果是段落,则更为方便,可用查找替换)

Sub LineCount()
Dim i As Integer, LineCount As Integer, Range1 As Long, Range2 As Range, l As String
On Error Resume Next
Application.ScreenUpdating = False
With CommandBars("Word Count")
.Visible = True
.Controls(2).Execute
l = .Controls(1).List(6)
.Visible = False
End With
LineCount = Int(Mid(l, 1, Len(l) - 1))
With Selection
.GoTo what:=wdGoToLine, which:=wdGoToLast
For i = LineCount To 1 Step -1
.EndKey unit:=wdLine, Extend:=wdExtend
If .Text Like "+*" = True Then .Range.Delete: .HomeKey unit:=wdLine, Extend:=wdExtend
.GoTo what:=wdGoToLine, which:=wdGoToPrevious
Next
End With
Application.ScreenUpdating = True
End Sub

如果是段落方法更妙:
先将段落标记替换为手动换行符,即查找:^p,替换为:^l,全部替换

再查找:选中使用通配符:查找:+*^l(意思为以"+"开头的任意手动换行的区域),替换为:"",空空,什么也不要输入,全部替换即可

最后再将手动换行符替换为段落标记:即查找:^l,替换为:^p,全部替换.

Published At
Categories with 服务器类
Tagged with
comments powered by Disqus