Word中英文标点符号转换

2022-03-23 06:12:12   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《Word中英文标点符号转换》,欢迎阅读!
标点符号,中英文,转换,Word
1."工具"→""→"Visual Basic 编辑器" 2."工具"→""→""

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:=wdReplaceAll End With Next

With ActiveDocument.Content.Find .ClearFormatting '不限定查找格式 .MatchWildcards = True '使用通配符

.Execute findtext:=strFind, replacewith:=strRep, Replace:=wdReplaceAll End With

Application.ScreenUpdating = True '恢复屏幕更新 End Sub


本文来源:https://www.wddqxz.cn/29654aa003d8ce2f0166238b.html

相关推荐