(使用Windows 10和MS Word 2016年全球模板是:Normal.dotx和Autoload.dotm附加的模板有些文档是:Reference.dotx)微软Word VBA:获取文档的附加模板
大家好,
我在VBA中获取文档的附加模板时出现问题。
我有一个全局模板,当我加载MS Word时调用Autoload.dotm。但是,对于某些特定的文档,它们使用附加的模板,而不是全局模板(Autload.dotm)或常规模板(Normal.dotx)。这个附加模板被称为Reference.dotx。
所以我使用ActiveDocument.AttachedTemplate。但是这会返回Autoload.dotm,而不是Reference.dotx。我需要找出在Developer-> Document Template-> Templates选项卡 - >文档模板中定义的附加模板是否为Reference.dotx。 (不要以为它会有所作为,但选中“自动更新文档样式”复选框。)有谁知道如何查找文档是否使用了Reference.dotx?我不需要任何返回的全局模板。
我使用的是设法得到附加的模板的代码很简单:
If (ActiveDocument.AttachedTemplate = "Reference.dotx") Then
PrepareDocument_enabled = True
End If
难道说是错误的路径?你可以使用'AttachedTemplate.Name和.Path'。你有没有尝试过'Debug.print activedocument.attachedtemplate.name'或'.path'? – Niclas
Nah。不幸的是,只是返回Normal.dotm。它甚至不会返回我添加的全局模板。:/ –
而这正是问题(?)。它无法找到文档reference.dotx。 – Niclas