How do I append Word templates to a new document in VB.NET?

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-05-05T12:58:27Z Indexed on 2010/05/06 4:28 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

I'm poking around to see if this app can be done. Basically the end user needs to create a bunch of export documents that are populated from a database.

There will be numerous document templates (.dot) and the end result will be the user choosing templates x y and z to include for documentation, click a button and have the app create a new Word document, append the templates, and then populate the templates with the appropriate data.

The reason it needs to be done in Word as opposed to something like Crystal Reports is that the user may customize some fields before printing the documents as it can vary from export to export.

Is this possible to do through VB.NET (VS 2010)?

I assume it is but I'm having difficulty tracking down a solution.

Or alternatively is there a better solution?

Here's what I have so far (not much I know)

Import Microsoft.Office.Interop

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim oWord As Word.Application Dim oDoc As Word.Document

oWord = CreateObject("Word.Application")
oWord.Visible = False
oDoc = oWord.Documents.Add

'Open templates x.dot, y.dot, z.dot

'Append above templates to new document created

'Populate new document

oWord.Visible = True

End Sub

End Class

Thanks.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about visual-studio-2010