Word VBA Range.Find 对象工作不正确
我发现一个有趣的事情:
在word 2010中,选择一些文本,然后运行以下VBA代码:
public Sub Test()
With Selection.Range.Find
MsgBox .Execute(Selection.Range.text)
MsgBox .Found
End With
End Sub
两个消息框都说“False”,但都应该是“True”。为什么?
I found an interesting thing:
In word 2010, select some text, and run the following VBA code:
public Sub Test()
With Selection.Range.Find
MsgBox .Execute(Selection.Range.text)
MsgBox .Found
End With
End Sub
Both the two message box say "False", but both should be "True". Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常有趣!
Word 2007 也表现出相同的行为。
奇怪的是,这不仅在您从 VBA 搜索时出现:如果您在文档中选择某些文本并按“查找”,查找对话框将默认显示所选文本作为目标。
按“查找下一个>” Word 显示错误消息“Word 已到达文档末尾...等”。
如果您修改文本以搜索并删除最后一个字符,则不会发生这种情况。 VBA 与此一致:以下代码有效!
没有解决...但证明与GUI是一致的。
哈!
Very interesting!
Word 2007 exhibits the same behaviour.
The curious thing is that this not only when you are searching from VBA: If you select some text in the doc and press "find", the find dialog displays as default the selected text as objective.
By pressing "Find Next >" Word displays an error message "Word has reached the end of the document ... etc".
This doesn't happen if you modify the text to search deleting the last character. VBA is consistent with that: the folowing code works!
Not solved ... but proved to be consistent with the GUI.
HTH!