Disaster! Range Find no longer works

G

G.G.Yagoda

All of a sudden Range Find stopped working on my machine, without rhyme
or reason.

Range can still do .Select .Copy .Cut .Information .Font etc., but
..Find is dead.

Selection.Find is still working, but that's an unacceptable substitute.

When I copied Greg Maxey's most recent code from the "Reqest for
Assessment" thread, his Range find *did* work, but his range "rngstory"
is dimmed as a Word.Range for the purpose of finding in different
stories.

My kingdom for a Range.Find. Please somebody help.
 
G

G.G.Yagoda

There were *no* changes in the code. It worked successfully for weeks.
Taken from Greg Maxey's Defined Terms code:

With myRange.Find
.Text = """*"""
.MatchWildcards = True
.Execute
'Strip quotation marks
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
. . . etc.

After programatically moving an inserted section from the bottom of the
document to the top, the myRange.Find failed and mysteriously changed
the font throughout to red.

When I wrote this snippet into Normal.dot it failed too:

Dim Rng as Range
Set Rng = ActiveDocument.Range
With Rng.Find
.Text = vbCr
.Execute
End With

Although I cannot write a Range.Find into my VBA code anymore, I can
receive code from the outside using Range.Find and it works.

Is this enough to go on, Jonathan? Has anyone every heard of this
happening before? It feels like the end of the world.
 
J

Jezebel

Are you saying the code fails, or that it is not finding what you expect it
to find? If the latter, is it perhaps that the Find object is retaining
formatting settings? -- you're not clearing formatting within this call, so
if a previous find were looking for (eg) blue text, then that will still
apply...
 
G

G.G.Yagoda

I'm saying Range.Find is dead. It does nothing at all. Range.Find is
passed over as if it were commented out, and VBA goes right on to the
next command.

Clear formatting is not an issue either. It is only text that's being
searched for, although there are certain qualifying lines after, such
as:

If Rng.Font.Color = wdColorBlueGray Then . . . etc.

Remember: the code worked perfectly for a long time, and failed only
after revising code from another, totally unrelated module which added
a section at the very top of the document and contained no .Find.

The changing of all text to red, with no command to do so, is a
baffling phenomonen. I was praying that somebody, somewhere down the
line, has encountered this freak occurrence. Red is certainly
appropriate for the May Day condition it announces.

Perhaps the strangest thing is that if you were to send me code with
Range.Find in it, that code would work on my machine. I would be happy
to send someone my simple "find a paragraph mark snippet" from
Normal.dot to test on his/her machine. But who would dare try it? Any
volunteers?
 
J

Jonathan West

G.G.Yagoda said:
There were *no* changes in the code. It worked successfully for weeks.
Taken from Greg Maxey's Defined Terms code:

With myRange.Find
.Text = """*"""
.MatchWildcards = True
.Execute
'Strip quotation marks
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
. . . etc.

After programatically moving an inserted section from the bottom of the
document to the top, the myRange.Find failed and mysteriously changed
the font throughout to red.

That is the key. The last time you did a manual find, you included
formatting. Add the following before the .Execute command

.Format = False

A more general fix for this kind of problem is in this article

Clear settings from Find and Replace dialog to prevent unexpected results
from future Find or Replace operations
http://www.word.mvps.org/FAQs/MacrosVBA/ClearFind.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

G.G.Yagoda

Thanks but .Format = False doesn't help.

After much experimentation I discovered that .MatchWildcards = True
makes .Range.Find work. But nothing else works.

I take it there are no brave volunteers out there willing to run my
defective .Range.Find code on their machines?
 
J

Jezebel

I think those of us with experience of these issues have concluded that the
problem is not with the code you've posted, but the context in which you are
running it. That, coupled with your vaguely offensive rejection of
suggestions already made.

Your assertions about Find being 'dead in the water' and 'nothing else
works' simply make no sense. Either your code project is outright corrupt
(unlikely, but it happens), or Find is failing because of previous
conditions that you're not clearing or screw-ups with your Range objects.
Single functions from working libraries don't fail in isolation.
 
G

G.G.Yagoda

Kindly note:

1) I did not reject any solutions offered, my machine rejected them.

2) I'm not *asserting* that my .Range.Find is dead, I'm stating a
fact. I do not post pleas for help in order to look like a fool.

3) I appreciate the suggestions received so far and hope others will be
forthcoming.

4) Your swingeing, apodictic expertise notwithstanding, Jezebel, I
notice that you did not volunteer to open up my snippet of code on your
machine.
 
J

Jezebel

Talk about heaping Pelion upon Ossa ... !

No, I didn't volunteer to open up your code, for reasons stated. You're
obviously looking for a magic fix to what is clearly a coding bug on your
part, the reality of which you refuse to accept. Your 'fact' is actually a
desperate assertion which, to everyone else, is obviously incorrect. Unless
you're prepared to open your mind a little, I guess you're stuffed.
 
G

G.G.Yagoda

If it's "clearly a coding bug on (my) part," how come it worked fine
then failed after not touching it? Where could the miscoding possibly
lie if the code wasn't changed?

My mind is wide open, so feed me the magic fix already!

Actually, we weren't talking about heaping Pelion upon Ossa . . . but
since you bring it up, are we to take it that it is you who reign on
Mt. Olympus, beyond the reach of us mortals?

Who'da thunk it. Which do you prefer, being posted or prayed to?
 
C

Chuck

Regarding the ClearFind article -- I thought that you only needed to do that
if you were doing a *Selection.Find* not a *Range.Find*? Am I
misunderstanding?
 
C

Chuck

Does Range.Find work in other subs/modules that you create yourself and are
not contained in the template that you're having problems with?

Try the new code I posted today in that separate thread and let me know how
it works...
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?Q2h1Y2s=?=,
Regarding the ClearFind article -- I thought that you only needed to do that
if you were doing a *Selection.Find* not a *Range.Find*? Am I
misunderstanding?
Yes :) You always should use .ClearFormatting before starting a new "Find"
process.

If you're having problems with Range.Find, it might be useful to look through
all the articles on the topic on the word.mvps.org site. Bill Coan has come
across a number of anomalies which apparently "kill" the thing, but really,
it's just getting "stuck" in a peculiar structure of the document.

In addition, I don't think anyone has asked if you're trying to use this to
automate Word from OUTSIDE Word (like from Excel or Access)?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
G

G.G.Yagoda

Chuck and Cindy, thanks so much for your interest.

Chuck - I couldn't find the thread you're referring to. Where exactly
is that "separate thread"? What's the subject line? Could you provide
a link?

The answer to your question about other documents is, after the
disaster, I could not successfully insert a .Range.Find in any
document, regular or template.

Cindy - No, nothing from the outside, it's all going on in Word. I
will search the MVP site for .Range.Find. The Coan article, by the
way, concerns Selection.Find as opposed to .Range.Find.

Again, thank you both for your assistance.
 
C

Chuck

The separate thread is the thread you referred to in a previous post in this
thread("Request for assessment" with the indexing code that Greg and I have
been collaborating on).
 
C

Cindy M -WordMVP-

<#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<VA.0000aa9c.008449e7@speedy>
<[email protected]>
Newsgroups: microsoft.public.word.vba.general
NNTP-Posting-Host: 237.47.76.83.cust.bluewin.ch 83.76.47.237
Lines: 1
Path: number1.nntp.ams.giganews.com!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!130.191.3.6.MISMATCH!newshub.sdsu.edu!logbridge.uoregon.edu!hammer.uoregon.edu!enews.sgi.com!msrnewsc1!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: number1.nntp.dca.giganews.com microsoft.public.word.vba.general:65932

Hi G.G.Yagoda,
The Coan article, by the
way, concerns Selection.Find as opposed to .Range.Find.
There's more than one article up there. Very few things related
to .Find are specific to the Selection object. Most also apply to
the Range object. So don't discard an article without reading it
before checking whether it only applies to the Selection object.
The answer to your question about other documents is, after the
disaster, I could not successfully insert a .Range.Find in any
document, regular or template.
I apologize for what I'm going to ask; it may already have been
covered in an earlier exchange, but I simply don't have the time
to wade through all the messages...

This happens, even after you've rebooted Windows and Word? It's
not just something that happens in a current session? And it
doesn't "unstick" if you use Edit/Find in the UI?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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