Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FP memo fields to a read only MS Word DOC Using OLE aut
Message
De
23/02/2001 13:41:04
 
 
À
23/02/2001 11:11:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00478472
Message ID:
00478973
Vues:
32
>Thanks yes I would like you to write me back. Thank You again.

Before passing information to a Word document, you need to prepare your Word document. To do this, I'll guide you through a simple example that you can follow.

First of all, we need to insert a Word object that will be easily accessible from the "outside". We will use something calles a "DocVariable". This is a Word variable that can take any string value. It will be replaced by whatever you choose. It's kind of like doing the following in VFP:

"Hi, my name is " + cName + "."

And then, we could associate a value to cName. Here's how we can do this in Word:

First, open a new Word document. Type the phrase "My name is " and leave the cursor one space after the word "is" (all without typing the quotes, of course.)

Then, go to the menu option "Field..." in "Insert". Choose the option "Document automation" in the left list box. Then click once on the "DocVariable" option in the right list box. If you look in the text field under both list boxes, you'll see that word added the expression "DOCVARIABLE". Now, you need to provide Word with the name of the DocVariable that you're creating. Let's type "cName" (this time, with the quotes and keeping a space between the word "DOCVARIABLE" and your variable name.)

Now, hit the OK button. You'll get back to your word document and, seemingly, nothing will have change. In reality however, you added an invisible variable with an empty string value after the word "is". If you want to see that it is there, you can go to the option "Tools" -> "Options" and in the tab "View", click the "Field codes" option. Hit the OK button and you'll see Word's definition of your variable in there. However, for our example's sake, we don't want this option set on. So, if you activated the "field codes" option, go back and uncheck it.

You can now save your word document (in our example, I will refer to it as being "C:\docvariable.doc", but you can save it anywhere and under any name) and close it.

Now, open a new Foxpro window and create an OLE reference to the Word document. Here's how I did it (typing the commands in VFP's command window):

Public oWord
oWord = CREATEOBJECT('Word.APPLICATION')
oWord.DisplayAlerts = .F.
oWord.documents.open("C:\docvariables.doc") &&Or your path instead of mine
oWord.ActiveDocument.variables("cName").Value = "Steve Sowers" &&We associate a value with our DocVariable
oWord.ActiveDocument.fields.Update
oWord.Visible = .T.

You should now see your document with the phrase "My name is Steve Sowers" showing. The code is pretty straightforward, all you need to do is set the different variables of a Word document to corresponding values in FoxPro. You only have two things to remember: 1) All the variables need to have something in them, you cannot leave a variable empty. 2) You must issue an Update call after you finished setting your variables or the changes won't show.

There is a lot of subtilities in here but you'll surely discover how useful this is by learning to use it. Anyway, I hope this helped and if you have other questions, I'll be happy to lend a helping hand.

Good luck, Stephane.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform