MS Engineers: Word 2003 Find/Change Automation from Excel 2003 cra

J

Joel Berry

This is a repost from an earlier post in the Excel->Programming forum. No one
has any ideas how to solve this over there. Since posting over there,
however, I have also tried to run this code as a Macro from within Powerpoint
2003, and I get the same results but a different error: "Method 'replacement'
of object 'Find' failed.": Yes, it crashes PowerPoint 2003, just like Excel
2003, so it must be Word's automation, type library or objects, or
something... Here's the post:

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 = "^pDescription"
.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

Any ideas? Thanks in advanced?
 
J

Joel Berry

Clarification: the "Method 'Replacement'..." message does not crash
Powerpoint; it occurs on the
<appWord.Selection.Find.Replacement.ClearFormatting> line.

The <.Text="^pDescription"> line, however, crashes both Powerpoint 2003 and
Excel 2003 when called in the macro (in the included code).

Also, note there should be a "." (period) between appWord and Selection in
the line: <appwordSelection.Find.Execute Replace:=wdReplaceAll> I forgot to
include it when I pasted the text. Thanks!
 
T

Tony Jollans

It works fine for me (Office 2003, no Service Packs applied). So either it
is something in the service packs - or, more likely, something in your
environment.

I note that you are doing a Find/Replace on a brand new ought-to-be-blank
document and so must have some content in your normal template. I wonder if
you have anything else in the normal template which might be causing you a
problem - some code, perhaps, which may be running in parallel with your
automation code.

One other thought occurs to me - and I don't know whether it might have an
effect or not. Are all your references correct? Or might you still be
referring to Word 10 libraries?
 
J

Joel Berry

Thanks, Tony, for replying. All my references are correct. I even uninstalled
them and reinstalled them to make sure that the Office 11 references were
used.

On the search issue, it's not a blank document. It's a text file that is
generated from a spreadsheet. From that point, it gets put into Microsoft
Word before this code is run. The search and replace is used to format the
text file: so I have two files: one, plain text, the other formatted, for use
in a page layout program.

I cannot get the code to run, even without the text file (i.e., just
creating a new macro in Excel that controls a search from Word.) It crashes
regardless.
 
T

Tony Jollans

Hi Joel,

I'm not really understanding what you're doing - what you say doesn't seem
to be reflected in the posted code. I suspect, however, that that's not
relevant.

I've gone back and re-read your original post and there are a couple of
things that don't make complete sense. For example "Replacement" is a
property, not a method - in the normal course of events that probably
wouldn't really matter, but in a Microsoft error message it's a bit
suspicious. I wonder, as you have suggested, if your object library is
somehow corrupt.. I would try Help > Detect and Repair first.
 

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