WORD中批量转换中英文标点符号

时间:2022-12-15 21:04:23 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
WORD中批量转换中英文标点符号

先记下一个东西:全角情况下,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:=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.wddqw.com/doc/22f66552ad02de80d4d840bb.html