Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filling formfields in Word.
Message
De
03/05/2007 18:29:43
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 8
OS:
Windows 2000 SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01222082
Message ID:
01222368
Vues:
18
This message has been marked as the solution to the initial question of the thread.
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform