Hi all,
We need to change the template files (.dot files) location in a lot of word documents.
Does MS Word exposes any interface for doing this programmatically?
Any other ideas on how to automate this would be appreciated.
TIA.
This is a discussion on changing tempate location in MS Word? within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, We need to change the template files (.dot files) location in a lot of word documents. Does MS ...
Hi all,
We need to change the template files (.dot files) location in a lot of word documents.
Does MS Word exposes any interface for doing this programmatically?
Any other ideas on how to automate this would be appreciated.
TIA.
<Signature
name="Ruchikar"
quote="discussions are forgotten, only code remains"/>
Open Word.
Tools-->Macros-->Visual Basic Editor.
View-->Object Browser.
Enter 'template' into the search box and click the search button.
Among the entries you will find the Document.AttachedTemplate property.
So:
If you really want a way to do this in C/C++ post back.Code:Set wdApp = CreateObject("Word.Application") Set wdDoc = wdApp.Documents.Open("path_to_my_doc.doc") wdDoc.AttachedTemplate = "my new template.dot" wdDoc.Save wdDoc.Close
Thanks!
Basically, I was thinking of making a commandline based exe to change the template files location in all the files in a particular folder.
I am not much of a VB chap, can you provide a similar explanation for C or C++.
<Signature
name="Ruchikar"
quote="discussions are forgotten, only code remains"/>
See DispHelper Thread.
You should reuse the one instance of word if you are altering several documents.Code:void SetTemplate(LPCTSTR szDoc, LPCTSTR szTemplate) { DISPATCH_OBJ(wdApp); dhCreateObject(L"Word.Application, NULL, &wdApp); dhCallMethod(wdApp, L".Documents.Open(%T)", szDoc); dhPutValue(wdApp, L".ActiveDocument.AttachedTemplate = %T", szTemplate); dhCallMethod(wdApp, L".ActiveDocument.Save"); dhCallMethod(wdApp, L".Quit"); SAFE_RELEASE(wdApp); }