Reputation: 187
I keep the template for the files I am working with in a dropbox and when I change to a computer with a different dropbox path, the template needs to be re-attached to the document. I would like to do this with a macro.
I can still see the name of the originally attached template in the "Templates and Add-Ins" Window, so the information must be somewhere stored within the document.
If however I try to retrieve the Name of the previously attached template via VBA by writing
strTemplate = ActiveDocument.AttachedTemplate
the result will be "Normal.dotm" and not "MyTemplate.dotm", which actually makes a lot of sense, but isn't what I am looking for.
Is there any way to retrieve the name and path of the previously attached template?
Upvotes: 1
Views: 1817
Reputation: 187
I found the answer here on stack overflow (unfortunately only after posting my question) as an answer to "How to open a word document without resolving the attached template?":
strOldTemplate = Dialogs(wdDialogDocumentStatistics).Template
Upvotes: 1
Reputation:
I think you can get the ful name (path+name) from
Application.Dialogs(wdDialogToolsTemplates).Template
and the name alone from
ActiveDocument.BuiltinProperties(wdPropertyTemplate)
The first time I tried the first of those, it didn't seem to work, but I could have been checking the wrong document. You won't find the Template property documented under the Dialog object - it's documented here
If those do not work, the only other ways I can see to do it would be
a. to look inside the .docx while it is closed (for a .docx), or maybe (I haven't checked) use dsofile.dll for a .doc, or
b. insert the field { template \p }, execute it and retrieve its result text
Upvotes: 1