How to open Word Document based on Template?
Posted on 2006-04-13
I have a VB.NET application that resides on notebooks which are disconnected from the Network most of the time.
I have a Word Document which is based on a template I've written.
The VB.NET application needs to be able to open up that document, save it as a new filename, change a few things, and then display it to the user.
I have no trouble with the opening, saving and changing part of this.
However, I get an error when I try to display this new document to the user on my test notebook:
"Word cannot open this document template. (C:\Program Files\...\Images\template1.dot"
The thing is, I've installed the template to the Application Data\Microsoft\Templates folder in the users Documents & Settings folder.
The C:\Program Files\...\Images folder is where the new document I created is saved.
If I actually open that document by double clicking, then it works fine.
But using the automation below it doesn't.
Dim objWord As New Word.ApplicationClass
Dim objDoc As Word.Document
Dim strDocPath as String = "C:\Program Files\...\Images\TestDocument.doc"
objWord.Visible = True
objDoc = objWord.Documents.Open(strDocPath)
objDoc .AttachedTemplate = "template1"
I'm sure this is to do with the template as I have no problems with other documents that use the Normal.dot template.
Can anybody help me?