# Opening up Word from VB



## wes peters (Nov 5, 2002)

I made a large text box and read my files into that, did the calculations.
Now I want to open word and place this info into word so I can fax it.

Any suggestions????

Thanks for the help


----------



## zeek zeon (Aug 1, 2002)

Why don't you open a file and output the data to it?

Something like:

Open "File.doc" for input as #1
write #1, data
close #1

I think from there you can use the shell command to open the file.

x="winword file.doc"
shell(x)

Two things, I'm not sure if you can pass arguments through the shell command, and where I wrote winword you would have to specify the path to winword on your computer.

Hope this is of some help.


----------



## YSB (Mar 7, 1999)

It sounds like what you want is DDE and a little OLE automation.

Its been a little while since I last did this so I hope I get it right here.

The basic concept is like this: First create a template Word document then you can open, save and close that document from within your program using OLE and you can "Poke" data into it using DDE.

Unfortunatly I don't have enough time tonight to do this with you step by step. What I *can* do is give you the basic commands you need and you should be able to fill in the rest with the help files.

In the word file, create Bookmarks and asign some random text to them using SET fields. Reference those bookmarks in the places where you want the text inserted using REF fields.

In your code open the word file, select its contents, and update the SET fields so the bookmarks will be recognized by DDE. The code will look something like this:

----------Code---------

Dim WordField As Variant
Dim WordObj as Object

Set WordObj = GetObject("_Pathname Of Word File_")

WordObj.Select

For Each WordField In WordObj.Fields
If WordField.Type = 6 Then WordField.Update 
' (comment) The Type number for a "SET" field is 6
Next

------------end code------------

Next you would use DDE to enter the data. Use DDEInitiate to start the link and create a "channel" for data transfer. Use DDEpoke to set the value of all your bookmarks to the data you want in the document. Next you would update all your REF fields to reflect the new values.

----------code----------

For Each WordField In WordObj.Fields
If WordField.Type = 3 Then WordField.Update 
' The type number for a "REF" field is 3
Next

-------------end code-------------

When you are done transfering data close the DDE channel with DDETerminate

You can then save, print or close the document using the methods of the WordObj Object.

Hope this helps you. Good Luck!

PS. Congratulations on being the recipient of my 1000th post on this board!


----------



## wes peters (Nov 5, 2002)

Thanks for all your help.

Got everything working.


----------

