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 curren开发者_开发知识库t find settings to a variable, run .Find(), then set the parameters back to what they were, but I can't figure it out.
At the end of your code, when you're done what you need to do, just set it back:
Set Find = r.Find(Text, LookIn:=xlValues, lookat:=xlPart)
From the msdn article:
Remarks The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.
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.
精彩评论