我正在使用 VSTO ThisAddIn 和 Word 2013。
我想使用 Find.Execute
将出现的一个字符串替换为另一个字符串,并使用自定义撤消消息标记此操作。代码是:
application.UndoRecord.StartCustomRecord("Some Message");
var find = application.ActiveDocument.Content.Find;
find.Execute("string to be replaced"
, ReplaceWith: "second string"
, Replace: WdReplace.wdReplaceAll);
application.EndCustomRecord();
所以我在这段代码运行期间发生了Word崩溃。如果我将 Replace: WdReplace.wdReplaceAll
更改为 Replace: WdReplace.wdReplaceOne
,我将可以使用文字,但我需要替换所有出现的内容。
有什么建议/解决方法吗?
最佳答案
当您有一个空的自定义撤消并执行全部替换时,Word 会出现一些问题。我今天刚遇到这个问题。
This page解释得很好。
选项
- 替换一个,然后替换全部
- 解决方法是在全部替换之前对文档进行更改,然后 撤消该更改
- 删除自定义撤消
关于c# - Word 2013 在查找.执行时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40508937/