Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the template path of a word 2003 document

Tags:

ms-word

vba

When I create a new document based on a template (*.dot), I need to know on which template is the document based on.

Is there a way to find out with VBA which template was used for creating this new document? I need the complete path to the template.

like image 807
Skuami Avatar asked Jul 01 '11 18:07

Skuami


2 Answers

ActiveDocument.AttachedTemplate.FullName
like image 150
Tim Williams Avatar answered Nov 11 '22 08:11

Tim Williams


You may also use a built-in document property to access the template name: ActiveDocument.BuiltInDocumentProperties(wdPropertyTemplate)

I don't remember why theres has been sometimes differences between the two results; you must try it out. please be aware that accessing sometimes the built-in properties sets the document in a dirty state, so that it is useful to save the ActiveDocument.Saved state before and reset it after having accessed the property.

[UPDATE] I've had again a look into the way you're creating the documents. If it's at your customer with 38.000 templates, I guess your problem are "fake" templates. I've just did a test with Office 2003:

  1. Create a new document "TestTemplate.doc" with same content and save it as doc file. Close it.
  2. Go to Windows Explorer and rename the document to "TestTemplate.dot". This provokes Windows Explorer to treat it as a template, not as a document. The default DDE command for templates is not "OPEN", but "NEW", what you can also see if you do a right-click on the file ("New" is bold, while with documents "Open" is bold).
  3. Double-click the fake template: Word creates a copy of the document, so a new file named "Document2" or whatsoever.
  4. Go to the VBA Editor, and type ?ActiveDocument.AttachedTemplate, and you'll see "Normal" as answer. Type ?activedocument.Type = wdTypeTemplate and you'll see "False" as answer.

Sp I guess the documents "Without template" are only copies of other documents, and not of templates. So you have no way to find the base template.

like image 4
domke consulting Avatar answered Nov 11 '22 08:11

domke consulting