View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Word 2003 Find/Change Automation from Excel 2003 crashes Excel

for the obvious reason.

--
Regards,
Tom Ogilvy

"Joel Berry" wrote in message
...
Thanks, Tom -- the error you got comes from my mistake: there should be a
period after "appWord" in that line of code -- I went through and added an
appWord object to specifiy the Selection object, since I was calling it

from
outside of Word. I just missed the period. That's probably why you got the
error...

"Tom Ogilvy" wrote:

I don't have xl2003 installed here, but running in xl2002 I got an error

in

appWordSelection.Find.Execute Replace:=wdReplaceAll

for the obvious reason. It did put an instance or word running in the

task
manager. It ran fine after that, but perhaps that might not be the case

in
xl2003. I would fix the code, then close excel. Make sure the task

manager
has no instances of word running, then try again.

--
Regards,
Tom Ogilvy

"Joel Berry" wrote in message
...
It worked perfectly under Excel XP (2002), but it hasn't worked yet

under
Excel 2003. Yes, there are all kinds of WINWORD.EXEs running in the

task
manager -- one for every time I have run this and it fails (which is

every
time). It runs the code perfectly until it gets to the <.Text=...

line,
and
then it crashes Excel!

"Tom Ogilvy" wrote:

Did it work the first time you ran it? Then develop problems.
Look in the task manager and see if you have multiple versions of

word
running

xl2000 purportedly had some problems using the with construct in an
automation environment. Perhaps the error has reappeared in xl2003.

Looks like you have created a reference to the Word Object model

(make
sure
it is the correct version), so constant definitions shouldn't be a

problem.

--
Regards,
Tom Ogilvy



"Joel Berry" wrote in message
...
Thanks, Tom.

You're right. The line is the "^pBREAK" line. I was testing it

again
with
a
different text to find. So, the line that is causing the crash is

the
".Text
= ^pBREAK" line.

The reason I posted it here is because it works flawlessly in Word

2003.
It's when you call it from a Word.Application object from within

Excel
that
it crashes. So, it's not necessarily a Word problem. Make sense?

"Tom Ogilvy" wrote:

There is no line

<.Text = "^pDescription"

regardless,
since all of this is performing actions in word, why not ask in

a
word
group
where you may have a higher probability of reaching someone who

knows
about
the word object model.

--
Regards,
Tom Ogilvy


"Joel Berry" wrote in

message
...
I just upgraded to Office Professional 2003 from Office

Professional
XP.

The following code, when executed, completely and irrevocably

crashes
Microsoft Excel 2003 at the line <.Text = "^pDescription". It

worked
just
find in Microsoft Excel XP. It even asks to send a report to
Microsoft.
Every
time. Easily reproducible. I have updated to all service
packs/patches,
etc.,
too.

Also, the line <Selection.Find.Replacement.ClearFormatting

gives
a
"Automation error: the procedure number is out of range"

error,
which
it
didn't do before in Excel 2003.

What the heck happened between the two versions? Now my code

has
completely
blown up!!! Any ideas????? Any help would be greatly

appreciated,
as
we
have
to get this program up and running for production! Thanks!!!

Public Sub Test()
Dim appWord As Word.Application

Set appWord = New Word.Application
appWord.Documents.Add

appWord.Selection.Find.ClearFormatting
appWord.Selection.Find.Replacement.ClearFormatting
With appWord.Selection.Find
.Text = "^pBREAK"
.Replacement.Text = "-----"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
appwordSelection.Find.Execute Replace:=wdReplaceAll

appWord.ActiveDocument.SaveAs "C:\TEST.DOC"
appWord.ActiveDocument.Close
appWord.Quit

Set appWord = Nothing

End Sub