本帖最后由 weiyingde 于 2017-4-24 06:24 编辑
在杜老师的指导和帮助,13907933959启发下,完成本程序,一键搞定段前、中、后所有多余空格(保留英文单词之间的一个半角空格),并对文本进行智能化格式。
对杜老师的指导和13907933959的帮助表示感谢。
代码如下:
Sub 空格的删除和文本的初步格式()
On Error Resume Next
With ActiveDocument.Content
.Find.Execute "^w", , , , , , , , , "^32", 2 '此句为关键句,将大片空格转为半角空格,便于后期机动处理,比如英文之间保留空格等。
.Find.Execute "([!A-Za-z])(^32)([!A-Za-z])", , , 1, , , , , , "\1\3", 2
.Find.Execute "([A-Za-z])(^32)([!A-Za-z])", , , 1, , , , , , "\1\3", 2
.Find.Execute "([!A-Za-z])(^32)([A-Za-z])", , , 1, , , , , , "\1\3", 2
.Find.Execute "^11", , , 1, , , , , , "^p", 2 '
.Find.Execute "(^32{1,})(*)(^13)", , , 1, , , , , , "\2\3", 2
.Find.Execute "(*)(^13)(^32{1,})", , , 1, , , , , , "\1\2", 2
With .Find
With .Replacement.Font
.Name = "方正姚体"
.ColorIndex = wdPink
End With
.Execute "[A-Za-a]", , , 1, , , , , , "^&", 2
End With
With .Find
With .Replacement.Font
.Name = "华文楷体"
.ColorIndex = wdBlue
End With
.Execute "[一-隝]", , , 1, , , , , , "^&", 2
End With
End With
With ActiveDocument
For i = 1 To .Paragraphs.Count
.Paragraphs(i).Format.CharacterUnitFirstLineIndent = 2
Next
End With
End Sub
|