wdDialogEditFind issue

Z

zSplash

Using "wdDialogEditFind", how can I set the find to be "" and the search
direction (i.e., Search Options: Search) to All? I have tried clearing the
find text, but the previous text is still in the dialogs form. I simply
can't figure out how to set the search criteria to All (from Down or Up).

TIA
 
H

Helmut Weber

Hi,
this is what I generally use:
Private Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
'---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
Z

zSplash

Thanks again, Helmut.

What I'm attempting to do is "clear" the various find options (i.e., Text,
MatchCase, MatchWholeWord, etc.). How can I do that without performing
another search? By that, I mean if I code:
Selection.FIND.ClearFormatting
With Selection.FIND
.Text = ""
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = False
End With

unless I perform a search, these new changes don't "stick". I tried using
SendKeys, as another option, but once I SendKeys "{ESC}", once again, the
new change don't "stick".

I woulda thunk (sic) "Selection.Find.ClearFormatting" woulda cleared
everything, but evidently "Down" and "MatchCase" are the default for me.
 
H

Helmut Weber

Hi,
strictly speaking, you can't clear the search options.
There is no "undefined" status. And there is no way,
to reset options, without performing a search, as far as I know.
But searching for nothing "" and replacing by nothing "" does
the job, and needs almost no time, as suggested with "ResetSearch",
which sets the options to the values an ordinary user would expect.
Search and replace operations, in my style of coding, invariably
start with "ResetSearch" and end with "ResetSearch",
which makes the core of the code very small and easy to read,
like:
Dim oRng As Range
Set oRng = ActiveDocument.Range
ResetSearch
With oRng.Find
.Text = "b"
.Replacement.Text = "x"
.Execute Replace:=wdReplaceAll
End With
ResetSearch
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
Z

zSplash

Helmut, you are wonderful.

Thanks so much for your assistance. Your code works beautifully, and it's
so sensible. Why didn't I think of it (don't have to answer that :)

st.
 
H

Helmut Weber

Thanks for the flowers.
Yet, not a perfect solution.
I am seeing some drawbacks, but I am hoping,
you'll never find out, what they are.
 

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