>Hi all
>I have been working in a little project for a customer.
>It is a simple vfp form where invoices for a particular client are displayed, chosen one at a time and then at the click of a button, using automation, a Word template-based invoice is created.
>The client wants a specific format and a .dot was provided.
>
>In my laptop it works very well, but today, when demoing it, I got a "OLE dispatch exception code 0 from Microsoft Word: This method or property is not available because the object refers to a protected area of the document..." error for each form field I tried to fill (I used Word2003 in my laptop, over there they have Word2000, live and learn)
>
>All goes down to this code, a function I call for every formfield:
>
>
>*-- Create word application
>o = CREATEOBJECT("word.application")
>
>*-- Create a document using template
>IF llUseSingle
> xx = o.Documents.Add(LCDOTPATH + "\XXX.dot")
>ELSE
> xx = o.Documents.Add(LCDOTPATH + "\YYY.dot")
>ENDIF
>
>FILLFIELD(CINVOICEDATE ,DTOC(curinvheader.dteinv))
>FILLFIELD(CINVOICENO,curinvheader.invno)
>.
>.
>FUNCTION FILLFIELD(cFieldName,cContent)
> o.ActiveDocument.FormFields.Item(cFieldName).Select
> *-- slow down a bit
> INKEY(0.1)
> *-- dirty trick to do a "select on entry" on the field
> o.Selection.Text = " "
> o.Selection.MoveRight(1,1)
> .Item(cFieldName).Select
> *-- slow down again
> INKEY(0.1)
> *-- Insert the content
> o.Selection.Text = cContent
>ENDFUNC
>
>
>This code works well on Word2003 with a protected doc, but not in Word2000,
>if I unprotect the document, fill fields and re-protect the document, the formfields will be overwritten, and the content will be unmodifiable, which is not good.
>
>Please help, it should be doable, perhaps I'm not using the correct methods/objects.
>
>TIA
>
>Max
Maximo,
You're not filling formfields in an official way, you're typing there:=) I guess it is a result of macro recording.
Filling formfields look like this:
* Set
.FormFields("Text1").Result = "My Text"
.FormFields("Check1").Checkbox.Value = .T.
.FormFields("DropDown1").Result = "My DD" && auto added if not in list
Check
Re: Anyone using MS Word 'Forms' as input documents? Thread #
1156885 Message #
1156906 fro a sample code.
Cetin