找到一个方法,是有点取巧,希望能帮到您:
来自Excel Home技术服务中心的技术专家:守柔
第一个宏:将全文中文标点符号替换为英文标点符号。第二个宏:将中文段落中的英文标点符号替换为中文标点符号。运行这两个宏就可以了。
注意:中文段落的起始字符必须为中文汉字,不得为空格等,以示区分。
******************************************************************************************
Sub ReplaceChineseInterpunctionInEnglish()
'全中文标点符号替换为英文标点符号
Dim ChineseInterpunction() As Variant,EnglishInterpunction() As Variant, N As Byte
'定义一个中文标点的数组对象
ChineseInterpunction = Array("。", ",", ";", ":", "?", "!", "……","—", "~", "〔", "〕", "《", "》", "‘","’", "“", "”")
'定义一个英文标点的数组对象
EnglishInterpunction = Array(".",",", ";", ":", "?", "!","…", "-", "~", "(", ")","<", ">", "'", "'","""", """")
On Error Resume Next
MsgBox UBound(EnglishInterpunction)
Application.ScreenUpdating =False '关闭屏幕更新
With ThisDocument.Content.Find
For N = 0 To16 '进行14次循环
.ClearFormatting '清除查找格式
'查找相应的英文标点,替换为对应的中文标点
.Executefindtext:=ChineseInterpunction(N), replacewith:=EnglishInterpunction(N),Replace:=wdReplaceAll
Next
End With
'恢复屏幕更新
Application.ScreenUpdating = True
End Sub
Sub ReplaceEnglishInterpunctionInChinese()
'中英互译文档中将中文段落中的英文标点符号替换为中文标点符号
Dim i As Paragraph, ChineseInterpunction() AsVariant, EnglishInterpunction() As Variant
Dim MyRange As Range, N As Byte
'定义一个中文标点的数组对象
ChineseInterpunction = Array("。", ",", ";", ":", "?", "!", "……","—", "~", "〔", "〕", "《", "》", "‘","’", "“", "”")
'定义一个英文标点的数组对象
EnglishInterpunction = Array(".",",", ";", ":", "?", "!","…", "-", "~", "(", ")","<", ">", "'", "'","""", """")
On Error Resume Next
Application.ScreenUpdating =False '关闭屏幕更新
For Each i InThisDocument.Paragraphs '遍历文档每个段落
If Asc(i.Range) < 0Then '如果段落首个字符为汉字(汉字字符的ASC<0)
'定义一个RANGE对象
ForN = 0 To 13 '进行14次循环
SetMyRange = i.Range '定义一个RANGE对象
WithMyRange.Find '查找
.ClearFormatting '清除查找格式
'查找相应的英文标点,替换为对应的中文标点
.Executefindtext:=EnglishInterpunction(N), replacewith:=ChineseInterpunction(N),Replace:=wdReplaceAll
EndWith
Next
End If
Next
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting '清除查找格式
.Text ="""" '查找"
'如果查找成功并且在中文段落中,分别将其替换为“/”
While .Execute
IfAsc(Selection.Paragraphs(1).Range) < 0 Then Selection.Text = "“"
If.Execute And Asc(Selection.Paragraphs(1).Range) < 0 Then Selection.Text ="”"
Wend
End With
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting '清除查找格式
.Text ="'" '查找'
While .Execute
'如果查找成功并且在中文段落中,分别将其替换为‘/’
IfAsc(Selection.Paragraphs(1).Range) < 0 Then Selection.Text = "‘"
If.Execute And Asc(Selection.Paragraphs(1).Range) < 0 Then Selection.Text ="’"
Wend
End With
'恢复屏幕更新
Application.ScreenUpdating = True
End Sub
温馨提示:答案为网友推荐,仅供参考