|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 lhteee 于 2024-1-25 09:33 编辑
Sub 标准格式设置()
'
' 格式设置 Macro
' 宏在 2008-9-23 由 陈凯 制作
'
Application.ScreenUpdating = False
'更改所有硬回车为软回车
Selection.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
.MatchAllWordForms = 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.Find.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
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
.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)
.Forward = 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 Integer '定义qjsz(全角数字)、bjsz(半角数字)为字符串型,iii为整数型
qjsz = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./<>?;’:[]{}\|=-+_)(*%$#@!`~&"
bjsz = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,。/《》?;':〔〕{}\|=-+_)(×%$#@!'~&"
Selection.WholeStory
For iii = 1 To 95 '循环10次
With Selection.Find
.Text = Mid(qjsz, iii, 1) 'mid函数:返回文本字符串中从指定位置开始的特定数目的字符,每次取一个数字
.Replacement.Text = Mid(bjsz, 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 = True
.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 '清除全文格式
Selection.Font.Size = 14 '设置字号为11号
'设置行距
Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle '设置为单倍行距
'Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceExactly '设置固定行距
'Selection.ParagraphFormat.LineSpacing = 20 '设置固定行距
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify '设置文本为两端对齐
Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 2 '设置段首缩进2字符
Selection.HomeKey unit:=wdStory '移至文首
Selection.EndKey unit:=wdLine, Extend:=wdExtend '选中首行
Selection.ClearFormatting '清除首行格式
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter '设置首行居中对齐
Selection.ParagraphFormat.LineUnitBefore = 1 '设置首行段前间距0行
Selection.ParagraphFormat.LineUnitAfter = 1 '设置首行段后间距0.5行
Selection.Font.Name = "方正小标宋简体" '设置首行字体为“宋体”
Selection.Font.Size = 16 '设置首行字号为14号
'Selection.Font.Bold = wdToggle '设置首行字形为加粗
Application.ScreenUpdating = True
End Sub
|
|