How to open Word Document based on Template?


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\"

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"
   objDoc .Activate()

I'm sure this is to do with the template as I have no problems with other documents that use the template.

Can anybody help me?

Many Thanks,
Who is Participating?
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages
janineoAuthor Commented:
Okay, I've worked out what the problem was.

When i created the document, I based it off the template which was in the same folder as the document when i saved it.

I re-created the document, basing it off the template in the Templates directory instead.

Then, when i ran the automation on the test PC it knew where to look for the template - the templates folder, not the same directory as the document.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.