Selection.FIND.ClearFormatting

Z

zSplash

I guess I just don't "get" what "Selection.FIND.ClearFormatting" actually
does. The problem I'm having is that past selection criteria remain in
effect, even though I've coded to clearformatting. So, simply, I guess,
what does Selection.Find.ClearFormatting "do"? (I've read the Help info on
the ClearFormatting Method, but it doesn't seem to be working in the
following code:)

Selection.FIND.ClearFormatting
With Selection.FIND
.Text = ""
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = False
.Execute
End With

For example, previously I performed a search with the criteria: Search for
"df", Search Up and MatchCase. After I run the above code, the Search
Options are still Search for "df" and SearchUp.

Maybe I should be asking how to set my default search options.

whew. TIA.
 
D

Dave Lett

Hi zSplash,

If you ran a search for .Font.Bold and then ran another search for "test"
without using .ClearFormatting, then Word would only find "test" that was
boldface. In short, ClearFormatting clears any formatting that you've set
when searching your document.

HTH,
Dave
 
Z

zSplash

Thank you, Dave. Of course, "ClearFormatting" means "ClearFormatting" on
the search. Any idea why my code doesn't successfully clear the search
options, though?

st.
 
H

Helmut Weber

Hi Noname,
a real name would be much nicer. ;-)
I am sorry about not having included all possible variations.
It seems, the suggestions of the dialog are depending on the
status of the selection. If the selection is extended, then
you may get the described effect, that options are not cleared.
I added "selection.collapse" at the beginning of "ResetSearch",
which seems to clear all.
---
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
Z

zSplash

Hi, Helmut. Thanks again. Maybe you can answer one more question along
this line: if I want, no matter what the previous "Find" may have selected
(i.e., Less or More in the dialogs box itself), for the "Find box" to always
show in "Less", what's the trick to achieving that?

(By the way, you're exceptionally good since you seem to deduce what I need!
For that, I give thanks, too.)

st.
 
Z

zSplash

This code seems to work, although it is visually unappealing when the
dialogs box opens/closes:
SendKeys "^f"
SendKeys "%{l}"
SendKeys "{ESC}"
 
H

Helmut Weber

Hi,
replace "more" by "more". and the dialog will remember it.
Like this:
Sub Test541()
With Selection.find
' .Parent.Collapse ' do not collapse the selection!
.ClearFormatting
.Replacement.ClearFormatting
.Text = "more"
.Replacement.Text = "more"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub
---
To the best of my knowledge.
But there are limits.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top