Sub ReplaceEnglishQuotesWithChineseQuotes()
Dim rng As Range
Dim quoteCount As Long
Dim singleQuoteCount As Long
Set rng = ActiveDocument.Content
quoteCount = 0
singleQuoteCount = 0
With rng.Find
.ClearFormatting
.Text = """"
.MatchWildcards = False
.Wrap = wdFindStop
Do While .Execute
quoteCount = quoteCount + 1
If quoteCount Mod 2 = 1 Then
rng.Text = "“" ' 中文左双引号
Else
rng.Text = "”" ' 中文右双引号
End If
rng.Collapse wdCollapseEnd
Loop
End With
' 重设范围,用于单引号替换
Set rng = ActiveDocument.Content
With rng.Find
.ClearFormatting
.Text = "'"
.MatchWildcards = False
.Wrap = wdFindStop
Do While .Execute
singleQuoteCount = singleQuoteCount + 1
If singleQuoteCount Mod 2 = 1 Then
rng.Text = "‘" ' 中文左单引号
Else
rng.Text = "’" ' 中文右单引号
End If
rng.Collapse wdCollapseEnd
Loop
End With
MsgBox "英文引号已成功替换为中文引号。", vbInformation
End Sub
-
打开 Word;
-
按下
Alt + F11
打开 VBA 编辑器; -
菜单栏 →
插入
→模块
; -
将上面的代码粘贴进去;
-
关闭编辑器;
-
在 Word 中按
Alt + F8
; -
选择
ReplaceEnglishQuotesWithChinese
→ 点击“运行”