Word宏代码集锦.docx
《Word宏代码集锦.docx》由会员分享,可在线阅读,更多相关《Word宏代码集锦.docx(36页珍藏版)》请在冰豆网上搜索。
Word宏代码集锦
Word宏代码集锦
一、修改word格式:
1、'智能去除选区软回车〔换行符〕
Sub智能去除选区软回车()
.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
.Text="^1^l"
.Replacement.Text="^&^p"
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^l"
.Replacement.Text=""
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
2、'去除选区多余空段
Sub去除选区多余空段()
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="^p^p"
.Replacement.Text="^p"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
3、'合并选区中“,〞完毕的多余分段
Sub合并选区多余分段()
.Text=",^p"
.Replacement.Text=","
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text="、^p"
.Replacement.Text="、"
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
4、'去除选区单字节空格
Sub去除选区单字节空格()
.Text=""
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
5、'去除选区单字节空格
Sub去除选区2单字节空格()
.Text=""
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
6、'去除选区1字空格
Sub去除选区1字空格()
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
7、'去除选区段首2字空格
Sub去除选区段首2字空格()
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
8、'去除选区Tab
Sub去除选区Tab()
.Text=vbTab
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
9、'增加选区空格
Sub增加选区空格()
.Text=" "
.Replacement.Text=" "
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
10、'选区段首缩进0字
Sub选区段首无缩进()
.Text=" "
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.LeftIndent=CentimetersToPoints(0)'左缩进0字符
.RightIndent=CentimetersToPoints(0)'右缩进0字符
.FirstLineIndent=CentimetersToPoints(0)'首行缩进点0公分
.CharacterUnitLeftIndent=0'左缩进单位0字符
.CharacterUnitRightIndent=0'右缩进单位0字符
.CharacterUnitFirstLineIndent=0
EndWith
.LeftIndent=CentimetersToPoints(0)'左缩进1字符
.RightIndent=CentimetersToPoints(0)'右缩进2字符
.CharacterUnitLeftIndent=0'左缩进单位0字符
.CharacterUnitRightIndent=0'右缩进单位0字符
.CharacterUnitFirstLineIndent=0
EndWith
EndSub
11、'选区段首缩进:
2字
Sub选区段首缩进2字()
.LeftIndent=CentimetersToPoints(0)'左缩进1字符
.RightIndent=CentimetersToPoints(0)'右缩进2字符
.FirstLineIndent=CentimetersToPoints(0.35)'首行缩进点单位公分
.CharacterUnitLeftIndent=0'左缩进单位0字符
.CharacterUnitRightIndent=0'右缩进单位0字符
.CharacterUnitFirstLineIndent=2
EndWith
EndSub
12、'选区段首缩进转空格—已完美
Sub选区段首缩进转空格()
Call选区段首无缩进
.Text="^p"
.Replacement.Text="^p "
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
.Text=" ^p"
.Replacement.Text=""
.MatchWildcards=False
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
EndSub
13、'选区段后间距1行
Sub选区段后间距1行()
Selection.ParagraphFormat.FirstLineIndent=CentimetersToPoints(0)
Selection.ParagraphFormat.LineUnitAfter=1
EndSub
14、'选区段后间距1行
Sub选区段前段后间距半行()
Selection.ParagraphFormat.FirstLineIndent=CentimetersToPoints(0)
EndSub
15、'选区段后间距1行
Sub选区段前段后无间距()
Selection.ParagraphFormat.FirstLineIndent=CentimetersToPoints(0)
Selection.ParagraphFormat.LineUnitBefore=0
Selection.ParagraphFormat.LineUnitAfter=0
EndSub
16、'去除选区图片
Sub去除选区图片()
.Text="^1"
.Replacement.Text=""
.MatchWildcards=True
EndWith
Selection.Find.ExecuteReplace:
=wdReplaceAll
En