Word宏代码集锦.docx
《Word宏代码集锦.docx》由会员分享,可在线阅读,更多相关《Word宏代码集锦.docx(49页珍藏版)》请在冰豆网上搜索。
Word宏代码集锦
Word宏代码集锦
一、 修改word格式:
1、' 智能清除选区软回车(换行符)
Sub 智能清除选区软回车()
WithSelection.Find
.Text="?
^l"
.Replacement.Text="^&^p"
.Forward=True
.Wrap=wdFindContinue
.Format=False
.MatchCase=False
.MatchWholeWord=False
.MatchByte=False
.MatchAllWordForms=False
.MatchSoundsLike=False
.MatchWildcards=True
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^1^l"
.Replacement.Text="^&^p"
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^l"
.Replacement.Text=""
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
2、' 清除选区多余空段
Sub 清除选区多余空段()
WithSelection.Find
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
3、' 合并选区中“,”结束的多余分段
Sub 合并选区多余分段()
WithSelection.Find
.Text=",^p"
.Replacement.Text=","
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.Find
.Text="、^p"
.Replacement.Text="、"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
4、' 清除选区单字节空格
Sub 清除选区单字节空格()
WithSelection.Find
.Text=""
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
5、' 清除选区单字节空格
Sub 清除选区2单字节空格()
WithSelection.Find
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
6、' 清除选区1字空格
Sub 清除选区1字空格()
WithSelection.Find
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
7、' 清除选区段首2字空格
Sub 清除选区段首2字空格()
WithSelection.Find
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
8、' 清除选区Tab
Sub 清除选区Tab()
WithSelection.Find
.Text=vbTab
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
9、' 增加选区空格
Sub 增加选区空格()
WithSelection.Find
.Text=" "
.Replacement.Text=" "
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
10、' 选区段首缩进0字
Sub 选区段首无缩进()
WithSelection.Find
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
WithSelection.ParagraphFormat
.LeftIndent=CentimetersToPoints(0) '左缩进0字符
.RightIndent=CentimetersToPoints(0) '右缩进0字符
.FirstLineIndent=CentimetersToPoints(0) '首行缩进点0公分
.CharacterUnitLeftIndent=0 '左缩进单位0字符
.CharacterUnitRightIndent =0 '右缩进单位0字符
.CharacterUnitFirstLineIndent=0
EndWith
WithSelection.ParagraphFormat
.LeftIndent=CentimetersToPoints(0) '