Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting a fields from one record into Word
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00449272
Message ID:
00449318
Views:
23
>Good Morning,
>
>I am using Automation to launch Word so that the user can generate a vendor survey form:
>
>
ox=CREATEOBJECT('word.document')
>ox.APPLICATION.documents.OPEN('c:\qcf19.doc')
>ox.APPLICATION.VISIBLE=.T.
>
>I'd like to be able to insert the vendor name, address, etc for the current record into Word programatically - can this be done?


Sure it can be done! Try something like this:
* Fire up Word, make it visible and add a document.
oWord = CreateObject('Word.Document')
oWord.Visible = .T.
oDocument = oWord.Documents.Add() 

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

* Create your text string
* cText = cMyvar + " " + cMyVar2 + CHR(13)
* Use CHR(13) to insert a paragraph return 

* Insesrt the text string.
oRange.InsertAfter(cText)
A good way to figure out what you want to do is to fire up Word and run through the steps interactively while recording a macro. Wherever the data goes, simply use your field name as the text. When done, stop the macro and examine it in the VBEditor (I use Alt-F11 to get there quickly, but I think it's under Tools | Macros | VBEditor). Open the Module, and you'll find some VB code. It's not too hard to translate to VFP <s>. There's a good KB article on how to do that at http://support.microsoft.com/support/kb/articles/Q160/0/64.asp (KB article #Q160064 if the link doesn't work).

Hope this helps!

- della
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform