Excel 2010 VBA:使用 Range.Find() 时如何保存/缓存查找参数?
我以前也这样做过,但已经很多年了。采取这段代码:
Set Find = r.Find(Text, LookIn:=xlFormulas, lookat:=xlWhole)
这在我拥有的宏中运行。问题是,当我使用 CTRL+F 进行常规查找时,我的宏代码中使用的参数会被保存。我通常喜欢在单元格内容中搜索,而不是像上面的代码那样搜索整个单元格。每次打开查找窗口时,扩展查找选项并取消选中“匹配整个单元格内容”有点痛苦。
我以前所做的是将当前查找设置保存到变量中,运行 .Find(),然后将参数设置回原来的值,但我无法弄清楚。
I've done this before, but it's been many years. Take this code:
Set Find = r.Find(Text, LookIn:=xlFormulas, lookat:=xlWhole)
This runs in a macro I have. The problem is that when I go to do a regular find with CTRL+F, the parameters used here in my macro code are saved. I normally like to search within the cell contents, not the whole cell like what the above code does. It's a bit of a pain to expand the find options and uncheck "Match entire cell contents" every time I open the find window.
What I used to do was save the current find settings to a variable, run .Find(), then set the parameters back to what they were, but I can't figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在代码结束时,当您完成需要做的事情时,只需将其设置回来:
At the end of your code, when you're done what you need to do, just set it back:
来自 msdn 文章:
我从未听说过任何检索和恢复“查找”对话框设置的方法。
我猜这些是 find 函数实现中的静态参数,实际上没有外部位置可以获取当前值。不影响查找功能的最佳选择是尝试使用“匹配”来重新实现当前功能。
From the msdn article:
I've never heard of any method of retrieving and restoring Find dialog settings.
I'm guessing these are static parameters in the find function implementation and there's actually no external place where you can get the current values. Your best bet for not impacting the find function is to try using "Match" to re-implement your current functionality.