开发者

How to get the template path of a word 2003 document

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 开发者_StackOverflow社区which template was used for creating this new document? I need the complete path to the template.


ActiveDocument.AttachedTemplate.FullName


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜