《word自动化排版宏.doc》由会员分享,可在线阅读,更多相关《word自动化排版宏.doc(7页珍藏版)》请在三一办公上搜索。
1、分享 word自动化排版宏 复制链接 自己制作的word自动化排版宏,水平低,很粗糙!还有一些功能未实现,希望高手多多指点,把里面一些多余的代码删减掉,另外再添加一些功能!例如怎样能循环判断最后一页如果只有不到三分之一页的几行时,通过减小行距和字号从而去除最后一页。再者就是大家比较认可的正规排版格式(字号、行距等等)是什么?我想通过做这个东西,我们能有效地提高工作效率,又无需借助其他软件。下面将全部代码奉上! Sub 格式设置() 格式设置 Macro 宏在 2008-9-23 由 陈凯 制作 Application.ScreenUpdating = False 更改所有硬回车为软回车 Sel
2、ection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = l .Replacement.Text = p .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWor
3、dForms = False End With Selection.Find.Execute Replace:=wdReplaceAll 去除所有空行 Dim i As Paragraph, n As Integer Application.ScreenUpdating = False For Each i In ActiveDocument.Paragraphs If Len(i.Range) = 1 Then i.Range.Delete n = n + 1 End If Next Application.ScreenUpdating = True 去除半角空格 Selection.Fin
4、d.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = .Replacement.Text = .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False
5、 End With Selection.Find.Execute Replace:=wdReplaceAll 去除全角空格 Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = .Replacement.Text = .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True
6、.MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll 替换非标准引号为标准引号 Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = (*) .Replacement.Text = ChrW(8220) & 1 & ChrW(8221) .Fo
7、rward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll 字母数字符号全角转半角 Macro Dim qjsz, bjsz As String, iii As Intege
8、r 定义qjsz(全角数字)、bjsz(半角数字)为字符串型,iii为整数型 qjsz = ,./?;:|=-+_)(*%$#!& bjsz = 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,。?;:【】)(! Selection.WholeStory For iii = 1 To 95 循环10次 With Selection.Find .Text = Mid(qjsz, iii, 1) mid函数:返回文本字符串中从指定位置开始的特定数目的字符,每次取一个数字 .Replacement.Text = Mid(b
9、jsz, iii, 1) 将用于替换的相应位置的半角数字 .Format = False 保留替换前的字符格式 .MatchWildcards = False .Execute Replace:=wdReplaceAll 用半角符号替换全角符号 End With Next iii 修改小数点错误 Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = (0-9)。(0-9) .Replacement.Text = 1.2 .Forward = Tr
10、ue .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll 设置字号 Selection.WholeStory全选 Selection.ClearFormatting清除全文格式 Selecti
11、on.Font.Size = 14设置字号为14号 设置行距 Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceExactly Selection.ParagraphFormat.LineSpacing = 25 Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify设置文本为两端对齐 Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 2设置段首缩进2字符 Selection.HomeKey Unit:=
12、wdStory移至文首 Selection.EndKey Unit:=wdLine, Extend:=wdExtend选中首行 Selection.ClearFormatting清除首行格式 Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter设置首行居中对齐 Selection.ParagraphFormat.LineUnitBefore = 1设置首行段前间距1行 Selection.ParagraphFormat.LineUnitAfter = 1设置首行段后间距1行 Selection.Font.Name = 微软雅黑
13、设置首行字体为“微软雅黑” Selection.Font.Size = 18设置首行字号为18号 Selection.Font.Bold = wdToggle设置首行字形为加粗 Application.ScreenUpdating = TrueEnd Sub普通浏览复制代码保存代码打印代码Sub格式设置()格式设置Macro宏在2008-9-23由陈凯制作Application.ScreenUpdating=False更改所有硬回车为软回车Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSe
14、lection.Find.Text=l.Replacement.Text=p.Forward=True.Wrap=wdFindContinue.Format=False.MatchCase=False.MatchWholeWord=False.MatchByte=True.MatchWildcards=False.MatchSoundsLike=False.MatchAllWordForms=FalseEndWithSelection.Find.ExecuteReplace:=wdReplaceAll去除所有空行DimiAsParagraph,nAsIntegerApplication.Scr
15、eenUpdating=FalseForEachiInActiveDocument.ParagraphsIfLen(i.Range)=1Theni.Range.Deleten=n+1EndIfNextApplication.ScreenUpdating=True去除半角空格Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSelection.Find.Text=.Replacement.Text=.Forward=True.Wrap=wdFindContinue.Format=False.Ma
16、tchCase=False.MatchWholeWord=False.MatchByte=True.MatchWildcards=False.MatchSoundsLike=False.MatchAllWordForms=FalseEndWithSelection.Find.ExecuteReplace:=wdReplaceAll去除全角空格Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSelection.Find.Text=.Replacement.Text=.Forward=True.
17、Wrap=wdFindContinue.Format=False.MatchCase=False.MatchWholeWord=False.MatchByte=True.MatchWildcards=False.MatchSoundsLike=False.MatchAllWordForms=FalseEndWithSelection.Find.ExecuteReplace:=wdReplaceAll替换非标准引号为标准引号Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSelection.F
18、ind.Text=(*).Replacement.Text=ChrW(8220)&1&ChrW(8221).Forward=True.Wrap=wdFindContinue.Format=False.MatchCase=False.MatchWholeWord=False.MatchByte=False.MatchAllWordForms=False.MatchSoundsLike=False.MatchWildcards=TrueEndWithSelection.Find.ExecuteReplace:=wdReplaceAll字母数字符号全角转半角MacroDimqjsz,bjszAsSt
19、ring,iiiAsInteger定义qjsz(全角数字)、bjsz(半角数字)为字符串型,iii为整数型qjsz=,./?;:|=-+_)(*%$#!&bjsz=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,。?;:【】)(!Selection.WholeStoryForiii=1To95循环10次WithSelection.Find.Text=Mid(qjsz,iii,1)mid函数:返回文本字符串中从指定位置开始的特定数目的字符,每次取一个数字.Replacement.Text=Mid(bjsz,iii,1)
20、将用于替换的相应位置的半角数字.Format=False保留替换前的字符格式.MatchWildcards=False.ExecuteReplace:=wdReplaceAll用半角符号替换全角符号EndWithNextiii修改小数点错误Selection.Find.ClearFormattingSelection.Find.Replacement.ClearFormattingWithSelection.Find.Text=(0-9)。(0-9).Replacement.Text=1.2.Forward=True.Wrap=wdFindContinue.Format=False.Match
21、Case=False.MatchWholeWord=False.MatchByte=False.MatchAllWordForms=False.MatchSoundsLike=False.MatchWildcards=TrueEndWithSelection.Find.ExecuteReplace:=wdReplaceAll设置字号Selection.WholeStory全选Selection.ClearFormatting清除全文格式Selection.Font.Size=14设置字号为14号设置行距Selection.ParagraphFormat.LineSpacingRule=wdLi
22、neSpaceExactlySelection.ParagraphFormat.LineSpacing=25Selection.ParagraphFormat.Alignment=wdAlignParagraphJustify设置文本为两端对齐Selection.ParagraphFormat.CharacterUnitFirstLineIndent=2设置段首缩进2字符Selection.HomeKeyUnit:=wdStory移至文首Selection.EndKeyUnit:=wdLine,Extend:=wdExtend选中首行Selection.ClearFormatting清除首行格
23、式Selection.ParagraphFormat.Alignment=wdAlignParagraphCenter设置首行居中对齐Selection.ParagraphFormat.LineUnitBefore=1设置首行段前间距1行Selection.ParagraphFormat.LineUnitAfter=1设置首行段后间距1行Selection.Font.Name=微软雅黑设置首行字体为“微软雅黑”Selection.Font.Size=18设置首行字号为18号Selection.Font.Bold=wdToggle设置首行字形为加粗Application.ScreenUpdating=TrueEndSub