I am trying to save and then restore the settings for the find box.
I've tried the following code, but the .style setting is always left as
'sdPart' instead of whatever the style name was before the procedure is
run.

Thanks for any advice.
---------------------------------------

Sub MessWithFindBox2()

Dim fFind As Find
Set fFind = Selection.Find

'*********************
With Selection.Find
.ClearFormatting
.Text = ""
.Style = "sdPart"
.Execute
End With
'*********************

Selection.Find.Style = fFind.Style

End sub

Re: Restore Find box settings by Vince

Vince
Wed Apr 13 20:08:27 CDT 2005

"sdPart" within quotes will be treated as a string and therefore it will
look for "sdPart" as through there is a style called "sdPart".

If you need the current formatting, you will just need to remove the
".clearformatting". It works like the Find and Replace box. When you select
some specific formatting and search, the next time you open the Find and
Replace box, the same formatting is shown by default. In order to clear
them, you do a ".clearformatting"

With Selection.Find
.Text = ""
.Execute
End With


"netloss" <netloss@metacrawler.com> wrote in message
news:1113427633.087032.154690@g14g2000cwa.googlegroups.com...
> I am trying to save and then restore the settings for the find box.
> I've tried the following code, but the .style setting is always left as
> 'sdPart' instead of whatever the style name was before the procedure is
> run.
>
> Thanks for any advice.
> ---------------------------------------
>
> Sub MessWithFindBox2()
>
> Dim fFind As Find
> Set fFind = Selection.Find
>
> '*********************
> With Selection.Find
> .ClearFormatting
> .Text = ""
> .Style = "sdPart"
> .Execute
> End With
> '*********************
>
> Selection.Find.Style = fFind.Style
>
> End sub
>



Re: Restore Find box settings by netloss

netloss
Thu Apr 14 13:07:08 CDT 2005

What I'm trying to do is save the settings before the procedure
'MessWithFindBox2' is run. So say for example, that the style I was
searching for before I run MessWIthFindBox2 is called 'style x'. I
declare a Find object called fFind, then set it equal to the current
settings of the find box (set fFind = Selection.find). Then the code
betw/ the lines of ********** runs. When that is done, I want to
restore the .style setting in the Find box to 'style x', so from the
user's point of view, nothing has changed.
Thanks.


Re: Restore Find box settings by Klaus

Klaus
Fri Apr 15 09:23:01 CDT 2005

Hi,

Something you might try:
-- Use Range.Find instead of Selection.Find in your macro. That =
shouldn't mess with the current settings in the Find dialog, and you =
don't need to reset anything.

Not sure why your code didn't work... Probably "Set fFind =3D =
Selection.Find" sets fFind as a reference to the object =
"Selection.Find", and if you mess with Selection.Find, fFind also gets =
changed.
Unfortunately, not all objects in VBA have a .Duplicate method to avoid =
this... You'd probably need to iterate over anything in .Find until you =
get at the elementary stuff or objects that do have a .Duplicate method, =
and store it ("fFindFont=3DSelection.Find.Font.Duplicate ..."). That =
might get terribly convoluted.

Regards,
Klaus
=20


"netloss" <netloss@metacrawler.com> schrieb im Newsbeitrag =
news:1113502028.465337.148590@l41g2000cwc.googlegroups.com...
> What I'm trying to do is save the settings before the procedure
> 'MessWithFindBox2' is run. So say for example, that the style I was
> searching for before I run MessWIthFindBox2 is called 'style x'. I
> declare a Find object called fFind, then set it equal to the current
> settings of the find box (set fFind =3D Selection.find). Then the code
> betw/ the lines of ********** runs. When that is done, I want to
> restore the .style setting in the Find box to 'style x', so from the
> user's point of view, nothing has changed.
> Thanks.
>