Using VB.Net to Generate MS Word Documents 
Author Message
 Using VB.Net to Generate MS Word Documents

Greetings to All !

I'm looking for a good book, article, or reference on how to use
VB.Net (not VB6) to programmatically generate MS Word
documents.  I'm looking for something that will walk me through
the process of spawning the document object and generating
a simple bogus report that contains a couple of headers (title,
page no, etc.) and some tab-aligned numerical data.  I'd also
like to see the use of changing the font, style and size of the
text.  Nothing to complex but a complete example.

I have a CC in hand ready to purchase this book right here
and right now if I can find it or someone shows me the way.

I'm using VB.Net and Office 2000 (and '97).  I don't want to
see VB6 examples as they don't translate so well to .Net.  Some
of the objects don't seem to work at all (like Word.Range) when
translating it to VB.Net.

Also, is there a way to add a reference to Office's Objects to
a VB.Net project so that it knows what all of the objects are?

I've gotten the following example to work via translating a VB6
example, but it was through a lot of trial and error:

Private Sub butMakeWordDoc_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles butMakeWord.Click
    Dim oWordApp As Object
    oWordApp = CreateObject("Word.Application")
    oWordApp.Documents.Add.SaveAs(FileName:="c:\test3.doc")

    Dim oWordDoc As Object
    oWordDoc = CreateObject("Word.Document")
    oWordDoc = oWordApp.ActiveDocument

    oWordDoc.Range.Font.Bold = True
    oWordDoc.Range.Font.Italic = True
    oWordDoc.Range.Font.Size = 16
    oWordDoc.Range.InsertAfter("This is a Word Document Test!!!!")
    oWordDoc.Range.InsertParagraphAfter()

    oWordDoc.Save()
    oWordDoc.Close()

    oWordApp.Quit()

    oWordApp = Nothing
    oWordDoc = Nothing
End Sub

Many Thanks!
---> Kelsey McClanahan
Newmont Mining Corp.



Tue, 06 Apr 2004 00:17:06 GMT  
 Using VB.Net to Generate MS Word Documents

Quote:
> Also, is there a way to add a reference to Office's Objects to
> a VB.Net project so that it knows what all of the objects are?
> I've gotten the following example to work via translating a VB6
> example, but it was through a lot of trial and error:

Project > Add Reference > COM Tab > Microsoft Word 9.0 Object Library

Then something like:

Dim x as new Word.Application

Hope this helps,
Jim



Tue, 06 Apr 2004 00:31:08 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Opening and Saving MS Word Documents using VB.NET

2. accessing word document through vb.net using word com object

3. opening and closing word document using vb,net

4. Trouble Opening a Word Document with VB.NET,Open member not found in Documents

5. Generating word document files from embedded documents in Access or SQL Server DB.

6. Automatic Generate a word-document from VB

7. Automatic Generate a word-document from VB

8. Automatic Generate a word-document from VB

9. Automatic Generate a word-document from VB

10. Automatic Generate a word-document from VB

11. Automatic Generate a word-document from VB

12. Automatic Generate a word-document from VB

 

 
Powered by phpBB® Forum Software