Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Reset Find/Replace settings?

Very odd behavior. I have a bit of standard VBA code that copies a
range, pastes its formulas to another range, selects that second
range, and then replaces a part of the formulas (so that I can have
two sets of ranges point at each other by templating one range only)
like so:

wks.Range("Rng1").Copy
wks.Range("Rng2").PasteSpecial xlPasteFormulas
wks.Range("Rng2").Replace What:="_1", Replacement:="_2",
LookAt:=xlPart

Works great, until...

....a user does a find/replace using the dialog box, chooses to search
within "Workbook" rather than "Sheet", at which point the .Replace
suddenly replaces _1 with _2 *everywhere*. VBA "remembers" Excel's
setting of where to search, despite the fact that I've called the
replace operation explicitly on the range. (Selecting the range in
code makes no difference, as usual.)

I've tried recording macros every which way to catch how Excel might
correct this, but no dice--seems like unless the user resets the
dialog, the VBA operation is doomed to fail overzealously.

I believe in Word there is a way to reinitialize that dialog. Does
this exist in Excel? Obviously, I can write my own little piece of
code that will find & replace just as effectively, but it seems to me
that this is the kind of thing a developer ought to be able to count
on "out of the (dialog!) box".

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Reset Find/Replace settings?

That is the side effect of doing a Find or a Find/Replace. Any settings you
change in code will persist and there is no way around it. The other problem
is that you can not read the settings in advance of changing them so that you
can put them back when you are done. The only thing you can do is to put back
settings that are not bound to cause a problem such as replace blank with
blank or such...
--
HTH...

Jim Thomlinson


"downwitch" wrote:

Very odd behavior. I have a bit of standard VBA code that copies a
range, pastes its formulas to another range, selects that second
range, and then replaces a part of the formulas (so that I can have
two sets of ranges point at each other by templating one range only)
like so:

wks.Range("Rng1").Copy
wks.Range("Rng2").PasteSpecial xlPasteFormulas
wks.Range("Rng2").Replace What:="_1", Replacement:="_2",
LookAt:=xlPart

Works great, until...

....a user does a find/replace using the dialog box, chooses to search
within "Workbook" rather than "Sheet", at which point the .Replace
suddenly replaces _1 with _2 *everywhere*. VBA "remembers" Excel's
setting of where to search, despite the fact that I've called the
replace operation explicitly on the range. (Selecting the range in
code makes no difference, as usual.)

I've tried recording macros every which way to catch how Excel might
correct this, but no dice--seems like unless the user resets the
dialog, the VBA operation is doomed to fail overzealously.

I believe in Word there is a way to reinitialize that dialog. Does
this exist in Excel? Obviously, I can write my own little piece of
code that will find & replace just as effectively, but it seems to me
that this is the kind of thing a developer ought to be able to count
on "out of the (dialog!) box".


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Reset Find/Replace settings?

I understand that the settings persist--it's an annoyance I can work
around.

My question is, is there something I can do on the VBA side to blow
them away before I start searching? There isn't even an analogous
argument in the VBA .Replace method to the Sheet/Workbook setting (or
the Search by or Look in settings, for that matter), since the method
is supposed to be limitable to a range...

Jim Thomlinson wrote:
That is the side effect of doing a Find or a Find/Replace. Any settings you
change in code will persist and there is no way around it. The other problem
is that you can not read the settings in advance of changing them so that you
can put them back when you are done. The only thing you can do is to put back
settings that are not bound to cause a problem such as replace blank with
blank or such...
--
HTH...

Jim Thomlinson


"downwitch" wrote:

Very odd behavior. I have a bit of standard VBA code that copies a
range, pastes its formulas to another range, selects that second
range, and then replaces a part of the formulas (so that I can have
two sets of ranges point at each other by templating one range only)
like so:

wks.Range("Rng1").Copy
wks.Range("Rng2").PasteSpecial xlPasteFormulas
wks.Range("Rng2").Replace What:="_1", Replacement:="_2",
LookAt:=xlPart

Works great, until...

....a user does a find/replace using the dialog box, chooses to search
within "Workbook" rather than "Sheet", at which point the .Replace
suddenly replaces _1 with _2 *everywhere*. VBA "remembers" Excel's
setting of where to search, despite the fact that I've called the
replace operation explicitly on the range. (Selecting the range in
code makes no difference, as usual.)

I've tried recording macros every which way to catch how Excel might
correct this, but no dice--seems like unless the user resets the
dialog, the VBA operation is doomed to fail overzealously.

I believe in Word there is a way to reinitialize that dialog. Does
this exist in Excel? Obviously, I can write my own little piece of
code that will find & replace just as effectively, but it seems to me
that this is the kind of thing a developer ought to be able to count
on "out of the (dialog!) box".



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Reset Find/Replace settings?

I always reset it -

On Error Resume Next
Set r = Cells.Find(What:="", _
LookIn:=xlFormulas, _
SearchOrder:=xlRows, _
LookAt:=xlPart, _
MatchCase:=False)
On Error GoTo 0

Reset the defaults

On Error Resume Next
Set r = Cells.Find(What:="", _
LookIn:=xlFormulas, _
SearchOrder:=xlRows, _
LookAt:=xlPart, _
MatchCase:=False)
On Error GoTo 0

Regards,
Peter T

"downwitch" wrote in message
ups.com...
Very odd behavior. I have a bit of standard VBA code that copies a
range, pastes its formulas to another range, selects that second
range, and then replaces a part of the formulas (so that I can have
two sets of ranges point at each other by templating one range only)
like so:

wks.Range("Rng1").Copy
wks.Range("Rng2").PasteSpecial xlPasteFormulas
wks.Range("Rng2").Replace What:="_1", Replacement:="_2",
LookAt:=xlPart

Works great, until...

...a user does a find/replace using the dialog box, chooses to search
within "Workbook" rather than "Sheet", at which point the .Replace
suddenly replaces _1 with _2 *everywhere*. VBA "remembers" Excel's
setting of where to search, despite the fact that I've called the
replace operation explicitly on the range. (Selecting the range in
code makes no difference, as usual.)

I've tried recording macros every which way to catch how Excel might
correct this, but no dice--seems like unless the user resets the
dialog, the VBA operation is doomed to fail overzealously.

I believe in Word there is a way to reinitialize that dialog. Does
this exist in Excel? Obviously, I can write my own little piece of
code that will find & replace just as effectively, but it seems to me
that this is the kind of thing a developer ought to be able to count
on "out of the (dialog!) box".



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Reset Find/Replace settings?

This is what I was looking for. It does the trick. And it only has to
be run once! ;)

Thanks to you both.

On Aug 1, 12:10 pm, "Peter T" <peter_t@discussions wrote:
I always reset it -

On Error Resume Next
Set r = Cells.Find(What:="", _
LookIn:=xlFormulas, _
SearchOrder:=xlRows, _
LookAt:=xlPart, _
MatchCase:=False)
On Error GoTo 0

Reset the defaults

On Error Resume Next
Set r = Cells.Find(What:="", _
LookIn:=xlFormulas, _
SearchOrder:=xlRows, _
LookAt:=xlPart, _
MatchCase:=False)
On Error GoTo 0

Regards,
Peter T

"downwitch" wrote in message

ups.com...

Very odd behavior. I have a bit of standard VBA code that copies a
range, pastes its formulas to another range, selects that second
range, and then replaces a part of the formulas (so that I can have
two sets of ranges point at each other by templating one range only)
like so:


wks.Range("Rng1").Copy
wks.Range("Rng2").PasteSpecial xlPasteFormulas
wks.Range("Rng2").Replace What:="_1", Replacement:="_2",
LookAt:=xlPart


Works great, until...


...a user does a find/replace using the dialog box, chooses to search
within "Workbook" rather than "Sheet", at which point the .Replace
suddenly replaces _1 with _2 *everywhere*. VBA "remembers" Excel's
setting of where to search, despite the fact that I've called the
replace operation explicitly on the range. (Selecting the range in
code makes no difference, as usual.)


I've tried recording macros every which way to catch how Excel might
correct this, but no dice--seems like unless the user resets the
dialog, the VBA operation is doomed to fail overzealously.


I believe in Word there is a way to reinitialize that dialog. Does
this exist in Excel? Obviously, I can write my own little piece of
code that will find & replace just as effectively, but it seems to me
that this is the kind of thing a developer ought to be able to count
on "out of the (dialog!) box".





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I reset VBA's setting to the default settings? Learning VBA[_2_] Excel Discussion (Misc queries) 3 April 5th 23 02:45 PM
Can Excel be reset to the original settings? Jugglertwo Excel Discussion (Misc queries) 3 March 24th 10 10:19 AM
How do i reset the settings to Excel defailt... anil Excel Discussion (Misc queries) 1 April 20th 07 09:40 AM
how do you reset the default settings and templates for Excel Ted Deguzman Setting up and Configuration of Excel 1 October 28th 06 02:20 AM
Determine Find/Replace settings and then restore them? Dan Williams Excel Programming 1 December 23rd 05 05:06 PM


All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"