views:

196

answers:

1

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.

A: 

Word documents can only be based on one .dot template: to create a new document based on a template you would pass the name of the template into the Documents.Add method. There's no way to apply multiple templates.

If you're targeting Word 2007 though you could accomplish this using 'building blocks'

Stuart Dunkeld
Damn, I find it hard to believe that it can't be done, oh well. How about opening a template and copying and pasting it into a new document, would that work (and preserve any addressable fields, images, etc.)?
Tom
I don't see any reason why that wouldn't work - although you wouldn't need a 'template' as such, using a .doc would work just as well.
Stuart Dunkeld