简体   繁体   English

如何获取word 2003文档的模板路径

[英]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.当我基于模板 (*.dot) 创建新文档时,我需要知道文档基于哪个模板。

Is there a way to find out with VBA which template was used for creating this new document?有没有办法通过 VBA 找出用于创建这个新文档的模板? 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)您还可以使用内置文档属性来访问模板名称: 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.请注意,有时访问内置属性会将文档设置为脏 state,因此在访问该属性之前保存 ActiveDocument.Saved state 并在访问该属性后重置它是有用的。

[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.如果您的客户有 38.000 个模板,我猜您的问题是“假”模板。 I've just did a test with Office 2003:我刚刚用 Office 2003 做了一个测试:

  1. Create a new document "TestTemplate.doc" with same content and save it as doc file.创建一个具有相同内容的新文档“TestTemplate.doc”并将其保存为 doc 文件。 Close it.关闭它。
  2. Go to Windows Explorer and rename the document to "TestTemplate.dot". Go 到 Windows Explorer 并将文档重命名为“TestTemplate.dot”。 This provokes Windows Explorer to treat it as a template, not as a document.这会促使 Windows Explorer 将其视为模板,而不是文档。 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).模板的默认 DDE 命令不是“OPEN”,而是“NEW”,如果您右键单击文件也可以看到(“New”是粗体,而文档“Open”是粗体)。
  3. Double-click the fake template: Word creates a copy of the document, so a new file named "Document2" or whatsoever.双击假模板: Word 创建文档的副本,因此创建一个名为“Document2”或其他名称的新文件。
  4. Go to the VBA Editor, and type?ActiveDocument.AttachedTemplate, and you'll see "Normal" as answer. Go 到 VBA 编辑器,然后键入?ActiveDocument.AttachedTemplate,您会看到“正常”作为答案。 Type?activedocument.Type = wdTypeTemplate and you'll see "False" as answer. Type?activedocument.Type = wdTypeTemplate 你会看到“False”作为答案。

Sp I guess the documents "Without template" are only copies of other documents, and not of templates. Sp 我猜“没有模板”的文件只是其他文件的副本,而不是模板的副本。 So you have no way to find the base template.所以你没有办法找到基础模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在多个Word模板中更改文档模板路径 - Change Document template path in multiple Word Templates 如何使用VBA将Word文档中的文本框值复制到其他Word文档中的文本框中(MS Word 2003) - How to copy textbox value in a word document into a textbox in a different word document with VBA (MS Word 2003) 如何使用 VBA 在 word 2003 文档中创建表格 - how to create a table in a word 2003 document using VBA 如何使用VBA获取word文档的磁盘路径? Document.Path 改为返回 web 路径 - How can I get the disk path of a word document using VBA? Document.Path returns the web path instead 将Word模板从MS Word 2003转换为MS Word 2007 - Convert Word template from MS Word 2003 to MS Word 2007 如何重新绘制 Word 2003 菜单栏 - How to repaint a Word 2003 menubar Word 2007 VB.net的SaveAs 2003 Word文档 - SaveAs 2003 word document from word 2007 VB.net 如何获取要放入Documents.open的文件路径,以便我可以在Word中使用第二个文档 - How to get the file path to put into the Documents.open so I can work with this 2nd document in Word 如何使用宏获取Word文档的当前文件名(没有扩展名或完整路径)? - How do I get the current filename of a Word document, without the extension or full path, using a macro? 如何将文本从Word文档转换为另一个Word文档 - How to get text from a Word document into another Word Document
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM