Word中英文引号替换为中文

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 → 点击“运行”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值