Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inserting a fields from one record into Word
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00449272
Message ID:
00449396
Vues:
16
>Let me be more specific. I want to open Word with a pre-typed letter in it (the two page survey) and simply insert the address information from the current VFP record at the top. (as I understand your example, it is creating a new document). I'll try to show my "concept" below:
>
>****************************************************************
>cName
>cAddr1
>cAddr2
>cCity, cState, cZip

>
>This is the beginning of the pre-existing letter, which is two pages in length...and it never changes..............
>***************************************************************

Sorry, I wrote the example so it worked on my machine -- I needed to add a document. But rest assured, oDocument = oWord.Documents.OPEN('c:\qcf19.doc'), as you had already found out, will work just fine.

If you set up the text of the document so that you can insert the requisite text before the document, you could do:
* Fire up Word, make it visible and add a document.
oWord = CreateObject('Word.Document')
oWord.Visible = .T.
oDocument = oWord.Documents.OPEN('c:\qcf19.doc') 

* Grab a reference to the document range:
oRange = oDocument.Range()

* Create your text string
#DEFINE CR CHR(13)
* cText = cName + CR + ;
         cAddr1 + CR + ;
         cAddr2 + CR + ;
         cCity + etc...

* Insert the text string.
oRange.InsertBefore(cText)
Of course, there are other ways to do it, two of which are finding a certain text string and replacing it with your own, or finding a bookmark. You could even write the whole document from scratch, including the text that never changes plopped in there from a memo field.

Again, I urge you to try to do the steps manually in Word, while you have the Macro Recorder turned on, then use the VBA code as a basis to find out what Word recorded.

- della
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform