How to open Word Document based on Template?

Posted on 2006-04-13
Last Modified: 2008-01-09

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,
Question by:janineo

    Author Comment

    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.



    Accepted Solution

    Closed, 500 points refunded.
    The Experts Exchange
    Community Support Moderator of all Ages

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now