vba - 错误替换双引号而不是双角引号 VBA Word

标签 vba ms-word

我正在尝试替换所有左右双角引号 chr(171) 和 chr(187),后跟一个空格 chr(32),即 «» 分别仅包含 chr(171) 或 chr(187)。

将此“« Abc ”替换为“«Abc

将此“xyz »”替换为“xyz»

我使用下面的代码,但替换后,字符是双引号而不是双角引号«

Sub ReplaceDoubleAngleQuotes()

With Selection.Find
 .ClearFormatting
 .Text = Chr(171) & Chr(32)
 .Replacement.ClearFormatting
 .Replacement.Text = Chr(171)
 .Execute Replace:=wdReplaceAll, Forward:=True, _
 Wrap:=wdFindContinue
End With

End Sub

如何解决这个问题?提前致谢。

最佳答案

可能您已打开 .AutoFormatAsYouTypeReplaceQuotes 并且您的 Word 正在将 chr(171) («) 更改为“”。

如果您只想为“查找和替换”功能关闭此功能,请执行以下操作:

Sub ReplaceDoubleAngleQuotes()

Dim userSmartQuotes As Boolean

userSmartQuotes = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = False

With Selection.Find
 .ClearFormatting
 .Text = Chr(171) & Chr(32)
 .Replacement.ClearFormatting
 .Replacement.Text = Chr(171)
 .Execute Replace:=wdReplaceAll, Forward:=True, _
 Wrap:=wdFindContinue
End With

Options.AutoFormatAsYouTypeReplaceQuotes = userSmartQuotes

End Sub

如果您只想关闭此功能(而不返回主设置),请输入

Options.AutoFormatAsYouTypeReplaceQuotes = False

在开始,仅此而已。

关于vba - 错误替换双引号而不是双角引号 VBA Word,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59624061/

相关文章:

sql-server - Excel vba xml解析性能

vba - 如何使用 PowerPoint VBA 自动执行延迟屏幕捕获/粘贴过程?

sql-server - 如何从 Excel 将记录插入 SQL Server

c# - 使用 c# 和 Interop 另存为 PDF 不将嵌入的 pdf 保存在 word 文档中

c# - 如何使用后期绑定(bind)访问 Microsoft Word 现有实例

excel - 使用错误处理根据列表框值删除工作表

mysql - Microsoft Access SQL查询两个表多对一

php - 使用 PHP 移除 MS Word "HTML"

r - 使用 texreg 和 Rmarkdown 获取 Word 文档

vba - 使用多个不连续选择