|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
为楼主简化了一些,但有些不敢确定,故请楼主自己斟酌吧!
- Sub 字符更正设置_New()
- ' 关闭屏幕刷新。(利于提高运行速度)
- ' Application.ScreenUpdating = False
- 'Sub 删除所有空格()
- Dim myRange As Range
- If Selection.Type = wdSelectionIP Then Selection.WholeStory
- Set myRange = Selection.Range
- myRange.Find.Execute FindText:=" ", replacewith:="", Replace:=wdReplaceAll '删除所有全角空格
- myRange.Find.Execute FindText:="^w", replacewith:="", Replace:=wdReplaceAll '删除所有空白区域
- 'Sub 替换全角数字字母为半角()
- Dim myRange As Range
- Set myRange = ActiveDocument.Content
- myRange.Find.ClearFormatting
- Do While myRange.Find.Execute(FindText:="[A-Za-z0-9]", Wrap:=wdFindStop, Format:=False, MatchWildcards:=True)
- myRange.CharacterWidth = wdWidthHalfWidth
- Set myRange = ActiveDocument.Range(myRange.End, ActiveDocument.Content.End)
- Loop
- 'A 全部替换为 B
- ActiveDocument.Content.Find.Execute FindText:="〇", replacewith:="○", Replace:=wdReplaceAll
- ActiveDocument.Content.Find.Execute FindText:="%", replacewith:="%", Replace:=wdReplaceAll, MatchWildcards:=False
- ActiveDocument.Content.Find.Execute FindText:="(", replacewith:="(", Replace:=wdReplaceAll '英文左括号全部替换为中文
- ActiveDocument.Content.Find.Execute FindText:=")", replacewith:=")", Replace:=wdReplaceAll '英文右括号全部替换为中文
- ' 将光标移到文档第1个字符前。
- Selection.HomeKey Unit:=wdStory
-
- ' 转换文档中的全角数值为半角数值。
- ' With Selection.Find
- ' .Text = "%"
- ' .Replacement.Text = "%"
- ' .Wrap = wdFindContinue
- ' .MatchWildcards = False
- ' End With
- ' Selection.Find.Execute Replace:=wdReplaceAll
- '
- With Selection.Find
- .Text = "([0-9]@).([0-9]@)"
- .Replacement.Text = "\1.\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
-
- ' 半角要点分隔点号转换成全角。
- With Selection.Find
- .Text = "([0-9]).([!0-9])"
- .Replacement.Text = "\1.\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
-
- ' 英文标点转换成中文标点。
- With Selection.Find
- .Text = "([!a-zA-Z]):([!a-zA-Z])"
- .Replacement.Text = "\1:\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
- With Selection.Find
- .Text = "([!a-zA-Z]),([!a-zA-Z])"
- .Replacement.Text = "\1,\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
- With Selection.Find
- .Text = "([!a-zA-Z]);([!a-zA-Z])"
- .Replacement.Text = "\1;\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
- With Selection.Find
- .Text = "([!a-zA-Z])\?([!a-zA-Z])"
- .Replacement.Text = "\1?\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
-
- ' 转换成标准文号括号。
- With Selection.Find
- .Text = "([\[[])([0-9]{4})([\]]])"
- .Replacement.Text = "〔\2〕"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
-
- ' 更换标准年份数字分隔符。
- With Selection.Find
- .Text = "([0-9]{4})[-—]([0-9]{4})"
- .Replacement.Text = "\1-\2"
- .Wrap = wdFindContinue
- .MatchWildcards = True
- End With
- Selection.Find.Execute Replace:=wdReplaceAll
-
- End Sub
复制代码 |
|