Alt+F11,然后插入-模塊:
復制下面代碼到編輯窗口:
Sub 半角標點符號轉換為全角標點符號() '中英互譯文檔中將中文段落中的英文標點符號替換為中文標點符號 Dim i As Paragraph, ChineseInterpunction() As Variant, EnglishInterpunction() As Variant Dim MyRange As Range, N As Byte '定義一個中文標點的數組對象 ChineseInterpunction = Array("。", ",", ";", ":", "?", "!", "……", "—", "~", "〔", "〕", "《", "》", "‘", "’", "“", "”") '定義一個英文標點的數組對象 EnglishInterpunction = Array(".", ",", ";", ":", "?", "!", "…", "-", "~", "(", ")", "<", ">", "'", "'", """", """") On Error Resume Next Application.ScreenUpdating = False '關閉屏幕更新 For Each i In ThisDocument.Paragraphs '遍歷文檔每個段落 If Asc(i.Range) < 0 Then '如果段落首個字符為漢字(漢字字符的ASC<0) '定義一個RANGE對象 For N = 0 To 13 '進行14次循環 Set MyRange = i.Range '定義一個RANGE對象 With MyRange.Find '查找 .ClearFormatting '清除查找格式 '查找相應的英文標點,替換為對應的中文標點 .Execute findtext:=EnglishInterpunction(N), replacewith:=ChineseInterpunction(N), Replace:=wdReplaceAll End With Next End If Next Selection.HomeKey wdStory With Selection.Find .ClearFormatting '清除查找格式 .Text = """" '查找" '如果查找成功並且在中文段落中,分別將其替換為“/” While .Execute If Asc(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 '如果查找成功並且在中文段落中,分別將其替換為‘/’ If Asc(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
然后Alt+F8,選擇剛剛添加的宏,並運行:
---分割線---
還有另一段代碼,簡潔一些:
Sub 全角轉換為半角() '使用前需先選中要替換的區域 Dim fullshape, halfshape As String, i As Integer '定義fullshape(全角)、halfshape(半角)為字符串型,i為整數型 fullshape = ",。?“”‘’!:;" halfshape = ",.?""''!:;" For i = 1 To 10 '循環10次 With Selection.Find .Text = Mid(fullshape, i, 1) 'mid函數:返回文本字符串中從指定位置開始的特定數目的字符,每次取一個標點符號 .Replacement.Text = Mid(halfshape, i, 1) '將用於替換的相應位置的半角標點符號 .Format = False '保留替換前的字符格式 .Execute Replace:=wdReplaceAll '用半角標點替換全角標點 End With Next i End Sub