Trying to find a string in a Word doc using automation from Access

B

bzamfir

Hi,

I need to find a string in a word document, usoing automation from Access.

I have the following code - oWrd is Word.application type object, created
with CreateObject():

oWrd.Documents.Open (cOldWordFile)
' start processing of word file

Dim myRange As Word.Range
Dim myFind As Word.Find
Set myFind = oWrd.ActiveDocument.Content.Find
myFind.Execute findText:="Categorie A1", Forward:=True

In this line, I get the error message "Automation error - The stub received
bad data"

This code works OK from a module created in Word document itself.

Does anyone knows what cause this?

Regards,
Bogdan
 
D

Doug Robbins - Word MVP

Hi Bzamfir,

Try dimming another object oWrdDoc and then

Set oWrdDoc = oWrd.Documents.Open (cOldWordFile)
Set myFind = oWrdDoc.Content.Find

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
B

bzamfir

Hi,
Try dimming another object oWrdDoc and then

Set oWrdDoc = oWrd.Documents.Open (cOldWordFile)
Set myFind = oWrdDoc.Content.Find

Thank you for your help.
I tried a slightly different version of the code before doing my current
version of the code.
It was as below:

Set oWrdDoc = oWrd.Documents.Open (cOldWordFile)
oWrdDoc.Content.Find.Execute (....)

and in that case, when I reach Execute line, Access gave me another error:
"Automation error - You ran out of memory."

This is stupid, since I have 512 MB ram, and a pagefile for 1 GB

Do you have any other idea?

Regards,
Bogdan
 
B

bzamfir

Hi,

I tryed again, this time I created both Document and Find objects, and
indeed the code worked.

Thank you vevy much.

Bogdan
 

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