“运行时错误 5692”是什么意思?意思是?
在某些情况下,range.Find.Execute
会抛出错误“运行时错误 5692”,包括有时当范围为空时,有时当使用正则表达式搜索完成时格式错误的正则表达式。
这个错误是什么意思?错误是否记录在任何地方?以我的无知来说,这是不可预测的。
The error "Runtime error 5692" gets thrown by range.Find.Execute
under some circumstances, including sometimes when the range is empty, and sometimes when a regex search is done with a malformed regex.
What does this error mean? Is the error documented anywhere? From my position of ignorance, it is unpredictable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我对 Word 2007(在 Crossover FWIW 下)的测试,我认为当“查找”文本 (Find.Text) 包含 Find.MatchWildcards 标志的无效字符时,就会发生这种情况。该标志是粘性的,因此,如果用户在上次手动查找或查找/替换时碰巧使用它,则 VBA 脚本将受到该粘性设置的污染,从而在您使用“^p”等字符时导致运行时错误 5692 和Find.Text 字符串中的“^t”。在运行 Find.Execute 之前显式设置“Find.MatchWildcards = False”可以防止出现错误。您可能会认为我们可以有一些文档或更好的错误消息。
总是失败的测试用例:
有效的测试用例:
Based on my testing with Word 2007 (under Crossover FWIW), I think this is occurring when the "Find" text (Find.Text) contains invalid characters for the Find.MatchWildcards flag. That flag is sticky, so if the user happened to use it on their last manual find or find/replace the VBA script would be contaminated with that sticky setting, resulting in the runtime error 5692 when you use characters such as '^p' and '^t' in your Find.Text string. Explicitly setting "Find.MatchWildcards = False" before running Find.Execute prevents the error. You'd think we could have had some documentation or a better error message though.
Test case that always fails:
Test case that works:
我做了一些研究,但是像你一样,我没有找到任何文档。
出现< /a> 该错误有时可能是由于未清除查找/替换文本引起的。
我已经使用几个不同的输入测试了下面的代码,并且它运行没有错误。
注意:代码需要勾选Tools ->参考文献-> Microsoft Word xx.0 对象库。
如果运行此代码时出现任何错误,请随时更新您的问题。
I did some research, but—like you—I found no documentation.
It appears that this error can sometimes be caused by not clearing find/replace text.
I have tested the code below with several different inputs, and it is running without errors.
Note: code requires checking Tools -> References -> Microsoft Word xx.0 Object Library.
Feel free to update your question with any errors you get while running this code.