• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

How to open Word Document based on Template?

Hi,

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

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?

Many Thanks,
Janine
0
janineo
Asked:
janineo
1 Solution
 
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.

Phew.

Cheers,
Janine
0
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now