Click to See Complete Forum and Search --> : Creating Word documents from within VB


law
July 16th, 2001, 02:29 PM
Hi there,

I 'd like to know if it is possible to create a word document from within Visual Basic, without starting MS Word itself, e.g. by using the Word Object library?!?

I want to create a new document, put text in it, not displaying any of this to the user and then save it to a .doc file.

Please help!

greetz Law

Andrew_Fryer
July 16th, 2001, 03:21 PM
Hello,

The only way I know of is to create a series of rtf statements and then write them to a file with a .doc extension. The file will then load.

The big problem is that rtf files are extremely difficult to create manually. My advice to you would be to create a blank rtf document to use as a template, which will contain all of the start and end information. Each new line in the document must start with a /par statement but I advise you to read up on the subject if you wish to do anything more complex as some of the commands are arcane to say the least.

Once you have the statements stored in the array or whatever it is simply necessary to write them in the same order as they were created to the .doc file. All the new statements should be inserted before the last one as this closes the document.

Hope this helps

Andrew

John G Duffy
July 16th, 2001, 06:39 PM
Actually, A .rtf file can be easily be created using the RichTextBox control.
Just enter your text and images into it and then use its SaveFile method. It will create all the Html stuff for you.

John G

John G Duffy
July 16th, 2001, 06:44 PM
Here is one example already posted in this forum. You might search this forum for other examples.
I found this one by going to "SEARCH' keying in "Word Document" and hitting the search button.
'
http://63.236.73.79/cgi-bin/bbs/wt/showpost.pl?Board=vb&Number=50721&Search=true&Forum=vb&Words=word%20document&Match=Whole&Topic=&Searchpage=0&Limit=25

John G

ant
July 16th, 2001, 06:51 PM
Try this:
First go under project | References, and check Microsoft Scripting Runtime (scrrun.dll)

Dim tex as Filesystemobject
Dim b
b = Freefile
set tex = new Filesystemobject
tex.createtextfile "C:\My Documents\mydocfile.doc"
Open "C:\My Documents\mydocfile.doc" for output as b
print #b, mytext.text
Close b



HTH

--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: christopherfolger@hotmail.com
for the address