
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.