WORD中批量转换中英文标点符号
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
先记下一个xx:
全角情况下,WORD中的空格为方格形状;半角情况下,空格为小黑点形状。
打开word,"工具"→"宏"→"Visual Basic编辑器",在主窗体复制以下内容后粘贴,保存.关闭编辑器,在"工具"→"宏"→"宏"里调用.
Sub ToggleInterpunction()'中英文标点互换
Dim ChineseInterpunction() As Variant, EnglishInterpunction() As Variant
Dim myArray1() As Variant, myArray2() As Variant, strFind As String, strRep As String
Dim msgResult As VbMsgBoxResult, N As Byte
'定义一个中文标点的数组对象
ChineseInterpunction = Array("、","。", ",", ";", ":
", "?", "!", "……", "—", "~","(", ")", "《", "》")
'定义一个英文标点的数组对象
EnglishInterpunction = Array(",",".", ",", ";", ":
", "?", "!", "…", "-", "~", "(", ")", "<",">")
'提示用户交互的MSGBOX对话框
msgResult = MsgBox("您想中英标点互换吗?按Y将中文标点转为英文标点,按N将英文标点转为中文标点!", vbYesNoCancel)
Select Case msgResult
Case vbCancel
Exit Sub '如果用户选择了取消按钮,则退出程序运行
Case vbYes '如果用户选择了YES,则将中文标点转换为英文标点
myArray1 = ChineseInterpunction
myArray2 = EnglishInterpunction
strFind = "“(*)”"
strRep = """\1"""
Case vbNo '如果用户选择了NO,则将英文标点转换为中文标点
myArray1 = EnglishInterpunction
myArray2 = ChineseInterpunction
strFind = """(*)"""
strRep = "“\1”"
End Select
Application.ScreenUpdating = False '关闭屏幕更新
For N = 0 To UBound(ChineseInterpunction) '从数组的下标到上标间作一个循环With ActiveDocument.Content.Find
.ClearFormatting '不限定查找格式
.MatchWildcards = False '不使用通配符
'查找相应的英文标点,替换为对应的中文标点
.Execute findtext:
=myArray1(N), replacewith:
=myArray2(N), Replace:
=wdReplaceAllEnd With
Next
With ActiveDocument.Content.Find
.ClearFormatting '不限定查找格式
.MatchWildcards = True '使用通配符
.Execute findtext:
=strFind, replacewith:
=strRep, Replace:
=wdReplaceAll
End With
Application.ScreenUpdating = True '恢复屏幕更新End Sub