2,462
社区成员
发帖
与我相关
我的任务
分享
Sub 删除段尾空格()
Dim i As Paragraph, mt, oRang As Range, n%, m%
Set regx = CreateObject("vbscript.regexp")
With regx
.Global = True: .IgnoreCase = False: .MultiLine = True
.Pattern = "\s+(\r)" '删除段落尾部的空格,如果没有\r,将会将回车符一并作为空格处理了。
For Each i In ActiveDocument.Paragraphs '在遍历各个段落
For Each mt In .Execute(i.Range.Text) '遍历所匹配的各个文本
m = mt.FirstIndex: n = mt.Length - 1 '查找的起始位置(从0开始计数)、长度
Set oRang = ActiveDocument.Range(i.Range.Start + m, i.Range.Start + m + n) '定位查找到的文本在整个文章中的起始位置、终止位置
Set myRange = i.Range
myRange.End = myRange.End - 1
myRange.Text = Left(formativetext, Len(formativetext) - 1)
'避免删除段尾换行符
Next
Next
End With
End Sub
Sub 删除段尾空格()
Dim i As Paragraph, mt, oRang As Range, n%, m%
Set regx = CreateObject("vbscript.regexp")
With regx
.Global = True: .IgnoreCase = False: .MultiLine = True
.Pattern = "\s+(\r)" '删除段落尾部的空格,如果没有\r,将会将回车符一并作为空格处理了。
For Each i In ActiveDocument.Paragraphs '在遍历各个段落
For Each mt In .Execute(i.Range.Text) '遍历所匹配的各个文本
m = mt.FirstIndex: n = mt.Length - 1 '查找的起始位置(从0开始计数)、长度
Set oRang = ActiveDocument.Range(i.Range.Start + m, i.Range.Start + m + n) '定位查找到的文本在整个文章中的起始位置、终止位置
i.Range.Select
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Range.Text=Left(.Replace(i.Range.Text, "$1"),Len(.Replace(i.Range.Text, "$1"))-1)
'避免删除段尾换行符
Next
Next
End With
End Sub
Sub 删除段尾空格()
Dim i As Paragraph, mt, oRang As Range, n%, m%, mRange As Range
Set regx = CreateObject("vbscript.regexp")
With regx
.Global = True: .IgnoreCase = False: .MultiLine = True
.Pattern = "\s+$" '删除 段落尾部的空格,如果没有\r,将会将回车符一并作为空格处理了。
For Each i In ActiveDocument.Paragraphs '在遍历各个段落
Set mRange = ActiveDocument.Range(i.Range.Start, i.Range.End - 1)
For Each mt In .Execute(mRange.Text) '遍历所匹配的各个文本
m = mt.FirstIndex: n = mt.Length '查找的起始位置(从0开始计数)、长度
Set oRang = ActiveDocument.Range(mRange.Start + m, mRange.Start + m + n) '定位查找到的文本在整个文章中的起始位置、终止位置
oRang.Text = .Replace(oRang.Text, "")
Next
Next
End With
End Sub
Sub 删除段尾空格()
Dim objFind As Find
Set objFind = ActiveDocument.Content.Find
objFind.Execute FindText:="^w^13", ReplaceWith:="^13", Replace:=wdReplaceAll
End Sub