Word 2000 Automation Problem

W

Wolfgang Kais

Dear Newsgroup.

I have the following problem with Word/Access 2000 (Windows 2000 Pro):
(I know, these are old versions, but my customer has not yet updated)

I want to automate the process of deleting all pagebreaks in an rtf file.
From withing MS Access, I'm trying to use the following automation code:

With WObj.Documents.Open(RTF_File)
With .Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute FindText:="^m", _
Forward:=True, _
Wrap:=wdFindContinue, _
Format:=False, _
ReplaceWith:="", _
Replace:=wdReplaceAll
End With
End With

(WObj is a new instance of the Word.Application class)

The function containing this code is called from a macro in MS Access.
The ClearFormatting method produces an error that is not trappable with
usual error handling and causes the macro in MS Access to halt.
When deleting the ClearFormatting line, .Replacement.ClearFormatting
causes an error ("method not supported") that can be trapped.
When also deleting the .Replacement.ClearFormatting line, .Execute
causes a trappable automation error: "The stub contained invalid data".

When running the same code ("With ActiveDocument.Range.Find") from
within Microsoft Word (2000), everything works perfectly fine.

Running the automation code in Word/Access 2003 (Windows XP)
everything's fine, too!

Can someone please give me a hint on how to remove all pagebreaks in an
rtf file using automation from MS Access 2000 as an automation client of
MS Word 2000?
 
C

Cindy M.

Hi Wolfgang,
The ClearFormatting method produces an error that is not trappable with
usual error handling and causes the macro in MS Access to halt.
I'm guessing you're running into the problem described in thes KB
articles

Find crashes Word automation code
.NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;313104

COM
http://support.microsoft.com/kb/292744/EN-US/

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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